2003-03-28 00:00:21 -05:00
|
|
|
#!/usr/local/bin/ruby
|
2015-12-16 00:31:54 -05:00
|
|
|
# frozen_string_literal: false
|
2003-03-28 00:00:21 -05:00
|
|
|
|
|
|
|
#
|
2003-04-24 09:37:32 -04:00
|
|
|
# pi.rb
|
2003-03-28 00:00:21 -05:00
|
|
|
#
|
2003-04-24 09: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 00:00:21 -05:00
|
|
|
#
|
|
|
|
|
2003-08-14 11:33:36 -04:00
|
|
|
require "bigdecimal"
|
|
|
|
require "bigdecimal/math.rb"
|
2003-03-28 00:00:21 -05:00
|
|
|
|
2003-08-14 11:33:36 -04:00
|
|
|
include BigMath
|
2003-03-28 00:00:21 -05:00
|
|
|
|
2003-08-14 11:33:36 -04:00
|
|
|
if ARGV.size == 1
|
2003-04-24 09:37:32 -04:00
|
|
|
print "PI("+ARGV[0]+"):\n"
|
2003-08-14 11:33:36 -04:00
|
|
|
p PI(ARGV[0].to_i)
|
|
|
|
else
|
2003-04-24 09:37:32 -04:00
|
|
|
print "TRY: ruby pi.rb 1000 \n"
|
2003-03-28 00:00:21 -05:00
|
|
|
end
|