home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsm / numbers / !NumModTxt / NumbersPi (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1995-09-27  |  1.8 KB  |  77 lines

  1.  >NumbersPi
  2. $+" at "+
  3.  "NumbersLib"
  4. numbers_initialise
  5.  "Number of decimal places ";places%
  6. one%=
  7. num_create
  8. temp%=
  9. num_create
  10.  Num_Set,one%,10
  11.  Num_Set,temp%,places%
  12.  Num_Pow,one%,temp%,one%
  13. num_create
  14.  which%=1 
  15.   t%=
  16. pi(which%,pi%)
  17.   t%=
  18.  OSCLI("spoolon "+file$)
  19.  'alg$
  20.  "That took ";t%/100;"S"
  21. num_prn(pi%)
  22.  *spool
  23.  which%
  24. num_destroy(pi%)
  25. num_destroy(temp%)
  26. num_destroy(one%)
  27. pi(w%,pi%)
  28.  Num_Set,pi%,0
  29. %I    alg$="Calculation using 24*ATN(1/8) + 8*ATN(1/57) + 4*ATN(1/239)"
  30. atan(24, 8, pi%)
  31. atan(8, 57, pi%)
  32. atan(4, 239, pi%)
  33. *I    alg$="Calculation using 20*ATN(1/8) + 8*ATN(1/18) + 12*ATN(1/57)"
  34. atan(20, 8, pi%)
  35. atan(8, 18, pi%)
  36. atan(12, 57, pi%)
  37. /;    alg$="Calculation using 16*ATN(1/5) - 4*ATN(1/239)"
  38. atan(16, 5, pi%)
  39. atan(-4, 239, pi%)
  40. 38    alg$="Calculation using 8*ATN(1/3) + 4*ATN(1/7)"
  41. atan(8, 3, pi%)
  42. atan(4, 7, pi%)
  43.  this computes n% * ATAN(1/k%) and adds it into result%
  44.  ATAN(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - ...
  45. atan(n%,k%,result%)
  46.  n1%,n2%,add%,k2%,iszero%
  47.   k2%=k%*k%
  48.   n1%=
  49. num_create
  50.   n2%=
  51. num_create
  52.   add%=
  53.  Num_ScalarMul,one%,
  54. (n%),n1%
  55.  Num_Set,n2%,0
  56.  Num_ScalarDiv,n1%,k%,n1%
  57.   n%=1
  58. K#    
  59.  Num_ScalarDiv,n1%,n%,n2%
  60.  add%>0 
  61. M(      
  62.  Num_Add,result%,n2%,result%
  63. N        
  64. O(      
  65.  Num_Sub,result%,n2%,result%
  66. P        
  67.     add%=-add%
  68.     n%+=2
  69. S$    
  70.  Num_ScalarDiv,n1%,k2%,n1%
  71. T%    
  72.  Num_Equals,n1%,0 
  73.  iszero%
  74.  iszero%
  75. num_destroy(n2%)
  76. num_destroy(n1%)
  77.