8 static char *
rcsid=
"@(#)$Id$";
45 if (isflt(a)) { fx=
intval(x); fy=
fltval(a);
goto flteqnum;}
46 else if (isint(a)) {
if (x!=a)
return(
NIL);}
50 else if (isratio(x)) {
66 if (fx!=fy)
return(
NIL);}
68 else if (pisbignum(x))
71 xv=bigvec(x); size=bigsize(x);
74 if (!isbignum(a))
return(
NIL);
75 if (size != bigsize(a))
return(
NIL);
77 for (i=0; i<size; i++)
if (xv[i]!=av[i])
return(
NIL);}
96 if (isint(right))
goto INTGT;
97 else if (isflt(right))
goto FLTGT;
98 else if (pisratio(right))
goto RATGT;
99 else if (pisbignum(right))
goto BIGGT;
107 else if (isflt(left)) { fright=
intval(right);
goto fltgt2;}
108 else if (isbignum(left)) {
110 right=left;
goto BIGGT; }
121 if (sign>=0)
return(
NIL);
124 else if (isflt(left)) {
128 else if (pisbignum(left)) {
130 if (comparison<=0)
return(
NIL);
133 else if (isratio(left))
goto RATGT; }
139 if (fleft<=fright)
return(
NIL);
160 if (isint(right))
goto INTLT;
161 else if (isflt(right))
goto FLTLT;
162 else if (pisratio(right))
goto RATLT;
163 else if (pisbignum(right))
goto BIGLT;
171 else if (isflt(left)) { fright=
intval(right);
goto FLTLT2;}
172 else if (isbignum(left)) {
174 right=left;
goto BIGLT; }
185 if (sign<0)
return(
NIL);
188 else if (isflt(left)) {
192 else if (pisbignum(left)) {
194 if (comparison>=0)
return(
NIL);
197 else if (isratio(left))
goto RATLT; }
203 if (fleft>=fright)
return(
NIL);
224 if (isint(right))
goto INTGE;
225 else if (isflt(right))
goto FLTGE;
226 else if (pisratio(right))
goto RATGE;
227 else if (pisbignum(right))
goto BIGGE;
235 else if (isflt(left)) { fright=
intval(right);
goto FLTGE2;}
236 else if (isbignum(left)) {
238 right=left;
goto BIGGE; }
249 if (sign>0)
return(
NIL);
252 else if (isflt(left)) {
256 else if (pisbignum(left)) {
258 if (comparison<0)
return(
NIL);
261 else if (isratio(left))
goto RATGE; }
267 if (fleft<fright)
return(
NIL);
288 if (isint(right))
goto INTLE;
289 else if (isflt(right))
goto FLTLE;
290 else if (pisratio(right))
goto RATLE;
291 else if (pisbignum(right))
goto BIGLE;
299 else if (isflt(left)) { fright=
intval(right);
goto FLTLE2;}
300 else if (isbignum(left)) {
302 right=left;
goto BIGLE; }
313 if (sign<0)
return(
NIL);
316 else if (isflt(left)) {
320 else if (pisbignum(left)) {
322 if (comparison > 0)
return(
NIL);
325 else if (isratio(left))
goto RATLE; }
331 if (fleft > fright)
return(
NIL);
344 x=ckintval(argv[0]); y=ckintval(argv[1]);
361 else if (isbignum(a)) {
381 else if (isbignum(a)) {
391 register eusinteger_t x_num, x_den, y_num, y_den, z_num, z_den, d1,d2,t;
393 x_num =
intval(x->c.ratio.numerator);
394 x_den =
intval(x->c.ratio.denominator);
395 y_num =
intval(y->c.ratio.numerator);
396 y_den =
intval(y->c.ratio.denominator);
400 z_num = x_num * y_den + x_den * y_num;
401 z_den = x_den * y_den;
404 t = x_num * (y_den / d1) + y_num * (x_den / d1);
408 z_den = (x_den / d1) * (y_den / d2);
415 register eusinteger_t x_num,x_den,y_num,y_den,z_num,z_den,d1,d2,t;
417 x_num =
intval(x->c.ratio.numerator);
418 x_den =
intval(x->c.ratio.denominator);
419 y_num =
intval(y->c.ratio.numerator);
420 y_den =
intval(y->c.ratio.denominator);
421 d1 =
gcd(x_den,y_den);
423 z_num = x_num * y_den - x_den * y_num;
424 z_den = x_den * y_den;
427 t = x_num * (y_den / d1) - y_num * (x_den / d1);
430 z_den = (x_den / d1) * (y_den / d2);
437 register eusinteger_t x_num,x_den,y_num,y_den,z_num,z_den,d1,d2;
439 x_num =
intval(x->c.ratio.numerator);
440 x_den =
intval(x->c.ratio.denominator);
441 y_num =
intval(y->c.ratio.numerator);
442 y_den =
intval(y->c.ratio.denominator);
446 z_num = (x_num / d1) * (y_num / d2);
447 z_den = (x_den / d2) * (y_den / d1);
455 register eusinteger_t x_num,x_den,y_num,y_den,z_num,z_den,d1,d2;
458 x_num =
intval(x->c.ratio.numerator);
459 x_den =
intval(x->c.ratio.denominator);
460 y_num =
intval(y->c.ratio.numerator);
461 y_den =
intval(y->c.ratio.denominator);
466 if(y_num >= 0) sign=1;
else sign=-1;
468 z_num = (x_num / d1) * (y_den / d2) * sign;
469 z_den =
abs((x_den / d2) * (y_num / d1));
484 if (isint(p)) num=
intval(p);
488 if (isint(q)) den=
intval(q);
497 else if (
intval(r->c.ratio.denominator)==1)
return(r->c.ratio.numerator);
519 else if (isflt(a)) { fs=is;
goto fplus;}
520 else if (pisratio(a)) { rs=
makeratio(is,1);
goto rplus;}
521 else if (pisbignum(a)) { b=
copy_big(a);
goto bigplus;}
529 else if (isflt(a)) { fs=
ratio2flt(rs);
goto fplus;}
552 else if (isbignum(a)) {
570 register pointer a=argv[0], rs, b, z;
580 else if (isratio(a)) {
584 else if (isbignum(a)) {
return(
big_minus(a));}
591 if (isint(a)) { is=
intval(a);
goto IMINUS;}
592 else if (isflt(a)) { fs=
fltval(a);
goto FMINUS;}
593 else if (pisratio(a)) { rs=
a;
goto RMINUS;}
594 else if (isbignum(a)) { b=
copy_big(a);
goto BIGMINUS;}
604 else if (isflt(a)) { fs=is;
goto FMINUS1;}
605 else if (pisratio(a)) { rs=
makeratio(is,1);
goto RMINUS1;}
606 else if (isbignum(a)) {
612 if (isint(z)) { vpop(); is=
intval(z);}
613 else { b=z;
goto BIGMINUS1;} }
622 else if (isflt(a)) { fs=
ratio2flt(rs);
goto FMINUS;}
645 if (isint(b)) { vpop();
goto IMINUS;}
649 else if (isbignum(a)) {
656 if (isint(b)) { vpop(); is=
intval(b);
goto IMINUS;}
680 if (isint(a)) { is=
intval(a);
goto ITIMES;}
681 else if (isflt(a)) { fs=
fltval(a);
goto FTIMES;}
682 else if (isratio(a)) { rs=
a; vpush(rs);
goto RTIMES;}
683 else if (isbignum(a)) { b=
copy_big(a); vpush(b);
goto BIGTIMES;}
693 if (s==0 || is==0) { is=0;
break;}
694 if (is<0) { sign= -1; is = -is;}
695 if (s<0) { sign= -sign; s = -
s;}
697 if( hi !=0 || (lo & ((
eusinteger_t)7 << WORD_SIZE-3))!=0) {
703 else if (isflt(a)) { fs=is;
goto FTIMES1;}
704 else if (pisbignum(a)) {
708 else if (pisratio(a)) {
720 else if (isflt(a)) { fs=
ratio2flt(rs);
goto FTIMES1;}
738 if (is<0) { sign = -sign; is= -is;}
742 if (isint(b)) { is=
intval(b); vpop();
goto ITIMES;}
746 else if (pisbignum(a)) {
755 if (isint(b)) { is=
intval(b); vpop();
goto ITIMES;}
757 else if (pisratio(a)) {
761 ctx->lastalloc= vpop();
784 if (isint(a)) is=
intval(a);
785 else if (isflt(a)) { fs=
fltval(a);
goto fquo;}
786 else if (pisratio(a)) {rs=
a;
goto rquo;}
787 else if (pisbignum(a)) { rs=
copy_big(a);
goto bquo;}
796 if (isflt(a)) { fs=is;
goto fquo2;}
797 else if (isint(a)) is/=
intval(a);
798 else if (pisratio(a)) { rs=
makeratio(is,1);
goto rquo;}
808 else if (isflt(a)) { fs=
ratio2flt(rs);
goto fquo;}
831 if (is<0) { sign = - sign; is= -is;}
962 else if (pisbignum(a)) {
979 if (isint(a))
return(a);
995 if (isint(a))
return(a);
1007 if (isint(a))
return(a);
1020 if (isint(a))
return(a);
1021 else if (isbignum(a))
return(a);
1033 extern double frexp(
double,
int *);
1050 if (isflt(a))
return(a);
1051 else if (isint(a)) { f=ckintval(a);
return(
makeflt(f));}
1077 if (
n==1)
return(a);
1079 else { fs=
fltval(a);
goto fmax;}
1082 if (isflt(a)) { fs=
intval(is);
goto fmax;}
1104 if (
n==1)
return(a);
1106 else { fs=
fltval(a);
goto fmin;}
1109 if (isflt(a)) { fs=
intval(is);
goto fmin;}
1125 {
int i=1,j,k,rsize,psize;
1130 r=
copy_big(r); rsize=bigsize(r); rbv=bigvec(r);
1137 if (isint(p)) k &=
intval(p);
1138 else if (isbignum(p)) {
1141 r=b; rsize=bigsize(r); rbv=bigvec(r);
1152 if (
intval(p)>=0)
for (j=1; j<rsize; j++) rbv[j]=0; }
1153 else if (isbignum(p)) {
1158 if (
big_sign(p)>0)
for (j=psize; j<rsize; j++) rbv[j]=0;}
1162 rsize=psize; rbv=bigvec(r);
1181 if (isbignum(p)) result |= bigintval(p);
1183 else result |=
intval(p);
1185 return(mkbigint(result));}
1195 else result ^=
intval(argv[i++]);
1217 else result &=
intval(argv[i++]);
1228 else result |=
intval(argv[i++]);
1258 index=ckintval(argv[0]);
1259 val=ckintval(argv[1]);
1261 if ((val>>index) & 1)
return(
T);
else return(
NIL);}
1268 register int firstone;
1272 count=ckintval(argv[1]);
1273 if (isint(argv[0])) {
1275 if (count<=0)
return(
makeint(val>>(-count)));
1276 if (val<=0) {
return(
makeint(val<<count));}
1278 if ((firstone + count)<WORD_SIZE-2) {
1279 sign=(val>=0)?1:(-1);
1281 if (sign>0)
return(
makeint(val));
1285 else if (isbignum(argv[0])) { a=argv[0]; sign=
big_sign(a);}
1289 {
int size=bigsize(a);
1294 av=bigvec(a); bv=bigvec(b);
1296 j= count/(WORD_SIZE-1); k=count % (WORD_SIZE-1);
1297 for (i=0; i<size; i++) {
1299 bv[i+j] |= (x << k);
1300 bv[i+j+1] = (x>>((WORD_SIZE-1)-k)); } }
1303 j=count/(WORD_SIZE-1); k=count % (WORD_SIZE-1);
1304 for (i=0; i<size-j-1; i++) {
1305 bv[i]=(av[j+i]>>k) | ((av[j+i+1]<<((WORD_SIZE-1)-k)) & MASK); }
1306 bv[size-j-1]=av[size-1]>>k;
1318 #if (WORD_SIZE == 64) 1319 register unsigned long val;
1321 register unsigned int val;
1324 val=ckintval(argv[0]); pos=ckintval(argv[1]);
1325 if (
n==3) width=ckintval(argv[2]);
1326 val=(val<<(WORD_SIZE-pos-width))>>(WORD_SIZE-width);
1334 #if (WORD_SIZE == 64) 1335 register unsigned long val,target,mask=~0;
1337 register unsigned int val,target,mask=~0;
1340 val=ckintval(argv[0]);
1341 target=ckintval(argv[1]);
1342 pos=ckintval(argv[2]);
1343 width=ckintval(argv[3]);
1344 mask=mask<<(WORD_SIZE-(pos+width));
1345 mask=mask>>(WORD_SIZE-width);
1348 target=(target & ~mask) | (val<<pos);
1371 state=Spevalof(RANDSTATE);
1372 if (state==UNBOUND) state=speval(RANDSTATE);}
1377 randval=erand48((
unsigned short *)state->c.ivec.iv);
1379 randval=erand48(state->c.ivec.iv);
1384 irandval=randval*imax;
1386 else if (isflt(a)) {
1388 frandval=randval*fmax;
pointer LOGNOT(context *ctx, int n, argv)
eusfloat_t big_to_float(pointer)
pointer DPB(context *ctx, int n, argv)
eusinteger_t div_int_big(eusinteger_t c, pointer x)
pointer ratio_divide(pointer x, pointer y)
pointer LDB(context *ctx, int n, argv)
pointer FREXP(context *ctx, int n, argv)
pointer return_ratio(pointer r)
pointer normalize_bignum()
pointer LSEQP(context *ctx, int n, argv)
eusfloat_t ratio2flt(pointer r)
pointer RANDOM(context *ctx, int n, argv)
pointer cons(context *, pointer, pointer)
pointer GREQP(context *ctx, int n, argv)
pointer eusfloat_to_big(float)
pointer LOGBITP(context *ctx, int n, argv)
pointer CEILING(context *ctx, int n, argv)
pointer ABS(context *ctx, int n, argv)
pointer TAN(context *ctx, int n, argv)
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
pointer ratio_plus(pointer x, pointer y)
pointer ASINH(context *ctx, int n, argv)
pointer int2ratio(eusinteger_t i)
pointer ACOSH(context *ctx, int n, argv)
pointer GREATERP(context *ctx, int n, argv)
pointer LOG(context *ctx, int n, argv)
pointer LESSP(context *ctx, int n, argv)
pointer LOGNOR(context *ctx, int n, argv)
pointer QUOTIENT(context *ctx, int n, argv)
void mul_int_big(eusinteger_t c, pointer x)
pointer ratio_times(pointer x, pointer y)
pointer LOGAND(context *ctx, int n, pointer argv[])
pointer PLUS(context *ctx, int n, argv)
pointer ATAN(context *ctx, int n, argv)
pointer ATANH(context *ctx, int n, argv)
void extended_mul(eusinteger_t d, eusinteger_t q, eusinteger_t r, eusinteger_t *hp, eusinteger_t *lp)
pointer LOGTEST(context *ctx, int n, argv)
pointer ADD1(context *ctx, int n, argv)
pointer MAX(context *ctx, int n, argv)
arith(context *ctx, pointer mod)
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
pointer SQRT(context *ctx, int n, argv)
pointer NUMEQUAL(context *ctx, int n, argv)
pointer COS(context *ctx, int n, argv)
pointer SIN(context *ctx, int n, argv)
pointer FLOOR(context *ctx, int n, argv)
pointer SUB1(context *ctx, int n, argv)
pointer EXP(context *ctx, int n, argv)
int big_compare(pointer x, pointer y)
pointer MIN(context *ctx, int n, argv)
pointer LOGIOR(context *ctx, int n, argv)
pointer MOD(context *ctx, int n, argv)
pointer ASH(context *ctx, int n, argv)
pointer extend_big(pointer, int)
pointer ROUND(context *ctx, int n, argv)
void complement_big(pointer x)
pointer LOGEQV(context *ctx, int n, argv)
pointer SINH(context *ctx, int n, argv)
pointer TANH(context *ctx, int n, argv)
pointer FLOAT(context *ctx, int n, argv)
pointer LOGNAND(context *ctx, int n, argv)
pointer TRUNCATE(context *ctx, int n, argv)
eusinteger_t big_sign(pointer)
pointer DECFLOAT(context *ctx, int n, argv)
pointer TIMES(context *ctx, int n, argv)
pointer MINUS(context *ctx, int n, argv)
pointer COSH(context *ctx, int n, argv)
pointer LOGXOR(context *ctx, int n, argv)
pointer ratio_minus(pointer x, pointer y)