2003-03-28 08:00:21 +03:00
|
|
|
#!/usr/local/bin/ruby
|
|
|
|
|
|
|
|
#
|
2003-04-24 17:37:32 +04:00
|
|
|
# pi.rb
|
2003-03-28 08:00:21 +03:00
|
|
|
#
|
2003-04-24 17:37:32 +04:00
|
|
|
# Calculates 3.1415.... (the number of times that a circle's diameter
|
|
|
|
# will fit around the circle) using J. Machin's formula.
|
2003-03-28 08:00:21 +03:00
|
|
|
#
|
|
|
|
|
2003-08-14 19:33:36 +04:00
|
|
|
require "bigdecimal"
|
|
|
|
require "bigdecimal/math.rb"
|
2003-03-28 08:00:21 +03:00
|
|
|
|
2003-08-14 19:33:36 +04:00
|
|
|
include BigMath
|
2003-03-28 08:00:21 +03:00
|
|
|
|
2003-08-14 19:33:36 +04:00
|
|
|
if ARGV.size == 1
|
2003-04-24 17:37:32 +04:00
|
|
|
print "PI("+ARGV[0]+"):\n"
|
2003-08-14 19:33:36 +04:00
|
|
|
p PI(ARGV[0].to_i)
|
|
|
|
else
|
2003-04-24 17:37:32 +04:00
|
|
|
print "TRY: ruby pi.rb 1000 \n"
|
2003-03-28 08:00:21 +03:00
|
|
|
end
|