diff options
author | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-14 15:33:36 +0000 |
---|---|---|
committer | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-14 15:33:36 +0000 |
commit | 67ea373c70104fba22bd33b4221881f21c29052d (patch) | |
tree | 9b4fe8b0af81b9f98493af0c45dec46f4202ae06 | |
parent | 9b1dbc0c774499c284dc55fffb15a8da3266d9a3 (diff) | |
download | ruby-67ea373c70104fba22bd33b4221881f21c29052d.tar.gz |
Changed to use lib/bigdecimal/math.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ext/bigdecimal/sample/pi.rb | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/ext/bigdecimal/sample/pi.rb b/ext/bigdecimal/sample/pi.rb index 833967a583..2f7dd27d60 100644 --- a/ext/bigdecimal/sample/pi.rb +++ b/ext/bigdecimal/sample/pi.rb @@ -3,48 +3,18 @@ # # pi.rb # - -require "bigdecimal" -# # Calculates 3.1415.... (the number of times that a circle's diameter # will fit around the circle) using J. Machin's formula. # -def big_pi(sig) # sig: Number of significant figures - exp = -sig - pi = BigDecimal::new("0") - two = BigDecimal::new("2") - m25 = BigDecimal::new("-0.04") - m57121 = BigDecimal::new("-57121") - u = BigDecimal::new("1") - k = BigDecimal::new("1") - w = BigDecimal::new("1") - t = BigDecimal::new("-80") - while (u.nonzero? && u.exponent >= exp) - t = t*m25 - u = t.div(k,sig) - pi = pi + u - k = k+two - end +require "bigdecimal" +require "bigdecimal/math.rb" - u = BigDecimal::new("1") - k = BigDecimal::new("1") - w = BigDecimal::new("1") - t = BigDecimal::new("956") - while (u.nonzero? && u.exponent >= exp ) - t = t.div(m57121,sig) - u = t.div(k,sig) - pi = pi + u - k = k+two - end - pi -end +include BigMath -if $0 == __FILE__ - if ARGV.size == 1 +if ARGV.size == 1 print "PI("+ARGV[0]+"):\n" - p big_pi(ARGV[0].to_i) - else + p PI(ARGV[0].to_i) +else print "TRY: ruby pi.rb 1000 \n" - end end |