ROUNDED.LOG 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. % Tests in the exact mode.
  3. x := 1/2;
  4. 1
  5. x := ---
  6. 2
  7. y := x + 0.7;
  8. 6
  9. y := ---
  10. 5
  11. % Tests in approximate mode.
  12. on rounded;
  13. y;
  14. 1.2
  15. % as expected not converted to approximate form.
  16. z := y+1.2;
  17. z := 2.4
  18. z/3;
  19. 0.8
  20. % Let's raise this to a high power.
  21. ws^24;
  22. 0.00472236648287
  23. % Now a high exponent value.
  24. % 10.2^821;
  25. % Elementary function evaluation.
  26. cos(pi);
  27. - 1
  28. symbolic ws;
  29. (!*sq ((!:rd!: . -1.0) . 1) t)
  30. z := sin(pi);
  31. z := 1.22460635382e-16
  32. symbolic ws;
  33. (!*sq ((!:rd!: . 1.2246063538224e-016) . 1) t)
  34. % Handling very small quantities.
  35. % With normal defaults, underflows are converted to 0.
  36. exp(-100000.1**2);
  37. 0
  38. % However, if you really want that small number, roundbf can be used.
  39. on roundbf;
  40. exp(-100000.1**2);
  41. 1.18441281937e-4342953505
  42. off roundbf;
  43. % Now let us evaluate pi.
  44. pi;
  45. 3.14159265359
  46. % Let us try a higher precision.
  47. precision 50;
  48. 12
  49. pi;
  50. 3.1415926535897932384626433832795028841971693993751
  51. % Now find the cosine of pi/6.
  52. cos(ws/6);
  53. 0.86602540378443864676372317075293618347140262690519
  54. % This should be the sqrt(3)/2.
  55. ws**2;
  56. 0.75
  57. %Here are some well known examples which show the power of this system.
  58. precision 10;
  59. 50
  60. % This should give the usual default again.
  61. let xx=e**(pi*sqrt(163));
  62. let yy=1-2*cos((6*log(2)+log(10005))/sqrt(163));
  63. % First notice that xx looks like an integer.
  64. xx;
  65. 2.625374126e+17
  66. % and that yy looks like zero.
  67. yy;
  68. 0
  69. % but of course it's an illusion.
  70. precision 50;
  71. 10
  72. xx;
  73. 2.6253741264076874399999999999925007259719818568888e+17
  74. yy;
  75. - 1.2815256559456092775159749532170513334408547400481e-16
  76. %now let's look at an unusual way of finding an old friend;
  77. precision 50;
  78. 50
  79. procedure agm;
  80. <<a := 1$ b := 1/sqrt 2$ u:= 1/4$ x := 1$ pn := 4$ repeat
  81. <<p := pn;
  82. y := a; a := (a+b)/2; b := sqrt(y*b); % Arith-geom mean.
  83. u := u-x*(a-y)**2; x := 2*x; pn := a**2/u;
  84. write "pn=",pn>> until pn>=p; p>>;
  85. agm
  86. let ag=agm();
  87. ag;
  88. pn=3.1876726427121086272019299705253692326510535718594
  89. pn=3.1416802932976532939180704245600093827957194388154
  90. pn=3.1415926538954464960029147588180434861088792372613
  91. pn=3.1415926535897932384663606027066313217577024113424
  92. pn=3.1415926535897932384626433832795028841971699491647
  93. pn=3.1415926535897932384626433832795028841971693993751
  94. pn=3.1415926535897932384626433832795028841971693993751
  95. 3.1415926535897932384626433832795028841971693993751
  96. % The limit is obviously.
  97. pi;
  98. 3.1415926535897932384626433832795028841971693993751
  99. end;
  100. (TIME: rounded 190 190)