本文整理汇总了C++中NUM函数的典型用法代码示例。如果您正苦于以下问题:C++ NUM函数的具体用法?C++ NUM怎么用?C++ NUM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NUM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _mpq_cmp_si
int
_mpq_cmp_si (mpq_srcptr q, long n, unsigned long d)
{
/* need canonical sign to get right result */
ASSERT (SIZ(DEN(q)) > 0);
if (SIZ(NUM(q)) >= 0)
{
if (n >= 0)
return _mpq_cmp_ui (q, n, d); /* >=0 cmp >=0 */
else
return 1; /* >=0 cmp <0 */
}
else
{
if (n >= 0)
return -1; /* <0 cmp >=0 */
else
{
mpq_t qabs;
SIZ(NUM(qabs)) = ABSIZ(NUM(q));
PTR(NUM(qabs)) = PTR(NUM(q));
SIZ(DEN(qabs)) = SIZ(DEN(q));
PTR(DEN(qabs)) = PTR(DEN(q));
return - _mpq_cmp_ui (qabs, NEG_CAST (unsigned long, n), d); /* <0 cmp <0 */
}
}
}
示例2: while
Object *Builtin_subtract(ListObject *arg, ListObject *context)
{
NumberObject *ret = NULL;
int i = 0;
while (i < arg->len)
{
Object *term = arg->arr[i];
if (Object_istype(term, NUMBER_OBJECT))
{
if (i == 0)
{
double init = NUM(term)->value;
if (arg->len == 1)
init = -init;
ret = new_NumberObject(init);
}
else
NUM(ret)->value -= NUM(term)->value;
}
else
{
if (ret != NULL)
del_Object(OBJ(ret));
ret = NULL;
break;
}
i++;
}
if (ret == NULL)
cause_error(INCORRECT_ARGUMENT_ERROR, "(<number> <number> ...)", 23);
return OBJ(ret);
}
示例3: mpq_set_ui
void
mpq_set_ui (MP_RAT *dest, unsigned long int num, unsigned long int den)
{
if (GMP_NUMB_BITS < BITS_PER_ULONG)
{
if (num == 0) /* Canonicalize 0/d to 0/1. */
den = 1;
mpz_set_ui (mpq_numref (dest), num);
mpz_set_ui (mpq_denref (dest), den);
return;
}
if (num == 0)
{
/* Canonicalize 0/n to 0/1. */
den = 1;
SIZ(NUM(dest)) = 0;
}
else
{
PTR(NUM(dest))[0] = num;
SIZ(NUM(dest)) = 1;
}
PTR(DEN(dest))[0] = den;
SIZ(DEN(dest)) = (den != 0);
}
示例4: main
int main(){
int n,k,year,m,i,j;
char mon[12][12]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
printf("输入年份\n");
scanf("%d",&year);
if(isleayear(year)==1 || year<2000)
n=(int)(fabs(year-2000)*365+(int)fabs(year-2000)/4)%7; //判断某年一月一号为星期几
else
n=(int)(fabs(year-2000)*365+(int)fabs(year-2000)/4+1)%7;
if(year<2000)n=7-n; //当年份小于2000是一月一号星期几
for(k=0;k<12;++k){
printf("%s\n日 一 二 三 四 五 六\n",mon[k]);
if(n==0) n+=7;
else
if(n==8)
n=1;
m=1;
for(j=0;j<n-1;++j)
printf(" ");
for(j=n-1;j<7;++j){
printf("%2d%c",m,j==6? '\n': ' ');
m=m+1;
}
for(i=1;i<=5;++i){
for(j=0;j<7&&m<=NUM(year,k);++j){
printf("%2d%c",m,j==6? '\n': ' ');
m=m+1;
if(m-1==NUM(year,k)){n=j+2;printf("\n");break;} //输出年历
}
}
}
return 0;
}
示例5: mpq_clear
void
mpq_clear (MP_RAT *m)
{
(*__gmp_free_func) (PTR(NUM(m)),
ALLOC(NUM(m)) * BYTES_PER_MP_LIMB);
(*__gmp_free_func) (PTR(DEN(m)),
ALLOC(DEN(m)) * BYTES_PER_MP_LIMB);
}
示例6: mpq_clear
void
mpq_clear (mpq_t m)
{
(*__gmp_free_func) (PTR(NUM(m)),
(size_t) ALLOC(NUM(m)) * GMP_LIMB_BYTES);
(*__gmp_free_func) (PTR(DEN(m)),
(size_t) ALLOC(DEN(m)) * GMP_LIMB_BYTES);
}
示例7: set_option_var
int
set_option_var(const option_t *options, const char *var, const char *val,
char *buf, size_t len)
{
char *s;
size_t i;
#define NUM(type) \
if (!*val) { \
*(type *)options[i].value = 1; \
break; \
} \
*(type *)options[i].value = (type)strsuftoll(options[i].desc, val, \
options[i].minimum, options[i].maximum); break
for (i = 0; options[i].name != NULL; i++) {
if (var[1] == '\0') {
if (options[i].letter != var[0])
continue;
} else if (strcmp(options[i].name, var) != 0)
continue;
switch (options[i].type) {
case OPT_BOOL:
*(bool *)options[i].value = 1;
break;
case OPT_STRARRAY:
strlcpy((void *)options[i].value, val, (size_t)
options[i].maximum);
break;
case OPT_STRPTR:
s = estrdup(val);
*(char **)options[i].value = s;
break;
case OPT_STRBUF:
if (buf == NULL)
abort();
strlcpy(buf, val, len);
break;
case OPT_INT64:
NUM(uint64_t);
case OPT_INT32:
NUM(uint32_t);
case OPT_INT16:
NUM(uint16_t);
case OPT_INT8:
NUM(uint8_t);
default:
warnx("Unknown type %d in option %s", options[i].type,
val);
return 0;
}
return i;
}
warnx("Unknown option `%s'", var);
return -1;
}
示例8: pdf_to_offset
fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj)
{
RESOLVE(obj);
if (obj < PDF_OBJ__LIMIT)
return 0;
if (obj->kind == PDF_INT)
return NUM(obj)->u.i;
if (obj->kind == PDF_REAL)
return (fz_off_t)(NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */
return 0;
}
示例9: pdf_to_real
float pdf_to_real(fz_context *ctx, pdf_obj *obj)
{
RESOLVE(obj);
if (obj < PDF_OBJ__LIMIT)
return 0;
if (obj->kind == PDF_REAL)
return NUM(obj)->u.f;
if (obj->kind == PDF_INT)
return NUM(obj)->u.i;
return 0;
}
示例10: apply_closure
PUBLIC INLINE void apply_closure(VMSTATE vms, OVECTOR closure, VECTOR argvec) {
if (closure == NULL || TAGGEDP(closure)) {
vm_raise(vms, (OBJ) newsym("invalid-callable"), (OBJ) closure);
} else if (closure->type == T_PRIM) {
int primargc;
prim_fn fnp = lookup_prim(NUM(AT(closure, PR_NUMBER)), &primargc);
if (fnp != NULL) {
if ((primargc >= 0 && argvec->_.length-1 != primargc) ||
(primargc < 0 && argvec->_.length-1 < -primargc))
vm_raise(vms, (OBJ) newsym("wrong-argc"), (OBJ) closure);
else
vms->r->vm_acc = fnp(vms, argvec);
} else
vm_raise(vms, (OBJ) newsym("invalid-primitive"), AT(closure, PR_NUMBER));
} else if (closure->type == T_CLOSURE) {
OVECTOR meth = (OVECTOR) AT(closure, CL_METHOD);
if (!MS_CAN_X(meth, vms->r->vm_effuid)) {
vm_raise(vms, (OBJ) newsym("no-permission"), AT(meth, ME_NAME));
return;
}
if (argvec->_.length-1 != NUM(AT(meth, ME_ARGC))) {
vm_raise(vms, (OBJ) newsym("wrong-argc"), (OBJ) meth);
return;
}
push_frame(vms);
vms->r->vm_env = argvec;
ATPUT(vms->r->vm_env, 0, AT(meth, ME_ENV));
vms->r->vm_lits = (VECTOR) AT(meth, ME_LITS);
vms->r->vm_code = (BVECTOR) AT(meth, ME_CODE);
vms->r->vm_self = (OBJECT) AT(closure, CL_SELF);
vms->c.vm_ip = 0;
vms->r->vm_method = meth;
if (NUM(AT(meth, ME_FLAGS)) & O_SETUID)
vms->r->vm_effuid = (OBJECT) AT(meth, ME_OWNER);
} else if (closure->type == T_CONTINUATION) {
int i;
VECTOR cstk = (VECTOR) AT(closure, CONT_STACK);
for (i = 0; i < cstk->_.length; i++)
ATPUT(vms->r->vm_stack, i, AT(cstk, i));
vms->c.vm_top = cstk->_.length;
restoreframe(vms, (OVECTOR) AT(closure, CONT_FRAME));
vms->r->vm_acc = AT(argvec, 1);
} else {
vm_raise(vms, (OBJ) newsym("invalid-callable"), (OBJ) closure);
}
}
示例11: mpq_set_num
void
mpq_set_num (mpq_ptr dest, mpz_srcptr num)
{
mp_size_t size = SIZ (num);
mp_size_t abs_size = ABS (size);
mp_ptr dp;
dp = MPZ_NEWALLOC (NUM(dest), abs_size);
SIZ(NUM(dest)) = size;
MPN_COPY (dp, PTR(num), abs_size);
}
示例12: scull_w_open
int scull_w_open (struct inode *inode, struct file *filp)
{
Scull_Dev *dev = &scull_w_device; /* device information */
int num = NUM(inode->i_rdev);
if (num > 0) return -ENODEV; /* 1 device only */
while (scull_w_count &&
(scull_w_owner != current->uid) && /* allow user */
(scull_w_owner != current->euid) && /* allow whoever did su */
!suser()) {
if (filp->f_flags & O_NONBLOCK) return -EAGAIN;
interruptible_sleep_on(&scull_w_wait);
if (current->signal & ~current->blocked) /* a signal arrived */
return -ERESTARTSYS; /* tell the fs layer to handle it */
/* else, loop */
}
if (scull_w_count == 0)
scull_w_owner = current->uid; /* grab it */
scull_w_count++;
/* then, everything else is copied from the bare scull device */
if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)
scull_trim(dev);
filp->private_data = dev;
MOD_INC_USE_COUNT;
return 0; /* success */
}
示例13: ALLOC
object *number_str(const char *s)
{
object *p = ALLOC(object);
TYPE(p) = OBJ_NUMBER;
sscanf(s, "%d", &NUM(p));
return p;
}
示例14: fillstat
static void
fillstat(Dir *d, uint32_t path)
{
Tab *t;
int type;
char buf[32];
memset(d, 0, sizeof(*d));
d->uid = estrdup("exec");
d->gid = estrdup("exec");
d->qid.path = path;
d->atime = d->mtime = time0;
d->length = 0;
type = TYPE(path);
t = &tab[type];
if(t->name)
d->name = estrdup(t->name);
else{
snprint(buf, sizeof buf, "%u", NUM(path));
d->name = estrdup(buf);
}
d->qid.type = t->mode>>24;
d->mode = t->mode;
}
示例15: scull_u_open
int scull_u_open (struct inode *inode, struct file *filp)
{
Scull_Dev *dev = &scull_u_device; /* device information */
int num = NUM(inode->i_rdev);
if (num > 0) return -ENODEV; /* 1 device only */
if (scull_u_count &&
(scull_u_owner != current->uid) && /* allow user */
(scull_u_owner != current->euid) && /* allow whoever did su */
!suser()) /* still allow root */
return -EBUSY; /* -EPERM would confuse the user */
if (scull_u_count == 0)
scull_u_owner = current->uid; /* grab it */
scull_u_count++;
/* then, everything else is copied from the bare scull device */
if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)
scull_trim(dev);
filp->private_data = dev;
MOD_INC_USE_COUNT;
return 0; /* success */
}