nbtest.red 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. % NBTEST.RED - Test Bignum Numeric transition points
  2. % And other numeric tests
  3. % M. L. Griss, 6 Feb 1983
  4. procedure fact N;
  5. Begin scalar m;
  6. m:=1;
  7. while n>0 do <<m:=m*n; n:=n-1>>;
  8. return m;
  9. End;
  10. on syslisp;
  11. syslsp procedure Ifact N;
  12. Begin scalar m;
  13. m:=1;
  14. while n>0 do <<m:=m*n; n:=n-1>>;
  15. return m;
  16. End;
  17. syslsp procedure ftest(n,m);
  18. for i:=1:n do fact m;
  19. syslsp procedure Iftest(n,m);
  20. for i:=1:n do ifact m;
  21. off syslisp;
  22. procedure Ntest0;
  23. Begin scalar n;
  24. N:=36;
  25. pos:=mkvect n;
  26. neg:=mkvect n;
  27. pos[0]:=1; neg[0]:=-1;
  28. for i:=1:N do <<pos[i]:=2*pos[i-1];
  29. neg[i]:=(-pos[i])>>;
  30. end;
  31. procedure show0 n;
  32. <<show(n,pos,'ntype0);
  33. show(n,neg,'ntype0)>>;
  34. procedure Ntest1;
  35. Begin scalar n;
  36. N:=40;
  37. newpos:=mkvect n;
  38. newneg:=mkvect n;
  39. newpos[0]:=1; newneg[0]:=-1;
  40. for i:=1:n do <<newpos[i]:=2*newpos[i-1];
  41. newneg[i]:=(-newpos[i])>>;
  42. end;
  43. procedure show1 n;
  44. <<show(n,newpos,'ntype1);
  45. show(n,newneg,'ntype1)>>;
  46. on syslisp;
  47. procedure NType0 x;
  48. case tag x of
  49. posint: 'POSINT;
  50. negint: 'negint;
  51. fixn: 'FIXN;
  52. bign: 'BIGN;
  53. fltn: 'fltn;
  54. default: 'NIL;
  55. end;
  56. procedure NType1 x;
  57. if Betap x and x>=0 then 'POSBETA
  58. else if Betap x and x<0 then 'NEGBETA
  59. else case tag x of
  60. posint: 'POSINT;
  61. negint: 'negint;
  62. fixn: 'FIXN;
  63. bign: 'BIGN;
  64. fltn: 'fltn;
  65. default: 'NIL;
  66. end;
  67. off syslisp;
  68. procedure show(N,v,pred);
  69. for i:=0:N do
  70. printf("%p%t%p%t%p%t%p%n",i,5,apply(pred,list(v[i])),20,v[i],40,float v[i]);
  71. end;