fpclass_t fpclass(double x) { int sign, exp; exp = EXPONENT(x); sign = SIGNBIT(x); if (exp == 0) { /* de-normal or zero */ if (HIFRACTION(x) || LOFRACTION(x)) /* de-normal */ return (sign ? FP_NDENORM : FP_PDENORM); else return (sign ? FP_NZERO : FP_PZERO); } if (exp == MAXEXP) { /* infinity or NaN */ if ((HIFRACTION(x) == 0) && (LOFRACTION(x) == 0)) /* infinity */ return (sign ? FP_NINF : FP_PINF); else if (QNANBIT(x)) /* hi-bit of mantissa set - quiet nan */ return (FP_QNAN); else return (FP_SNAN); } /* if we reach here we have non-zero normalized number */ return (sign ? FP_NNORM : FP_PNORM); }
int *iota(int start, int stop, int step){ if(stop == 0 && step == 0){ stop = start; start = 0; } if(step == 0){ step = SIGNBIT(stop - start); } int count = (stop-start)/step; int *ret = xmalloc(count*sizeof(int)); int i, x; for(i = 0, x = start; i<count; i++, x += step){ ret[i] = x; } return ret; }
int f_mult(int An, int SRn) { register int EXP; register int WAnMANT; int AnS, MAG, AnMANT; AnS = SIGNBIT(An, 15); MAG = AnS? (16384 - (An >> 2)) & 8191 : An >> 2; /* { register int mag = MAG << 1; for (EXP = 0; mag >>= 1; EXP++) ; } */ AnMANT = MAG ? LSHIFT(MAG, EXP - 6) : 1 << 5; EXP += ((SRn >> 6) & 15); WAnMANT = (((SRn & 63) * AnMANT) + 48) >> 4; MAG = LSHIFT(WAnMANT, 19 - EXP) & 32767; return ((SRn >> 10) ^ AnS ? (65536 - MAG) & 65535 : MAG); }
REAL Vec2::angle() const { Vec2 n=this->normal(); REAL angle=ACOS(n.x); return SETSIGN(angle,SIGNBIT(n.y)); }