bfloat.tst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. on time;
  2. 123/100;
  3. %this used the ordinary rational number system;
  4. on bigfloat;
  5. %now we shall use big-floats;
  6. ws/2;
  7. %Note that trailing zeros have been suppressed, although we know
  8. %that this number was calculated to a default precision of 10;
  9. %Let us raise this to a high power;
  10. ws**24;
  11. %Now let us evaluate pi;
  12. pi;
  13. %Of course this was treated symbolically;
  14. on numval;
  15. %However, this will force numerical evaluation;
  16. ws;
  17. %Let us try a higher precision;
  18. precision 50;
  19. pi;
  20. %Now find the cosine of pi/6;
  21. cos(ws/6);
  22. %This should be the sqrt(3)/2;
  23. ws**2;
  24. %Here are some well known examples which show the power of the big
  25. %float system;
  26. precision 10;
  27. %the usual default again;
  28. let xx=e**(pi*sqrt(163));
  29. let yy=1-2*cos((6*log(2)+log(10005))/sqrt(163));
  30. %now ask for numerical values of constants;
  31. on numval;
  32. %first notice that xx looks like an integer;
  33. xx;
  34. %and that yy looks like zero;
  35. yy;
  36. %but of course it's an illusion;
  37. precision 50;
  38. xx;
  39. yy;
  40. %now let's look at an unusual way of finding an old friend;
  41. nn := 8$
  42. a := 1$ b := 1/sqrt 2$ u:= 1/4$ x := 1$
  43. for i:=1:nn do
  44. <<y := a; a := (a+b)/2; b := sqrt(y*b); %arith-geom mean;
  45. u := u-x*(a-y)**2; x := 2*x;
  46. write a**2/u>>;
  47. %the limit is obviously:
  48. pi;
  49. end;