Created June 16, 2011 15:51
-
-
Save simonbaird/1029552 to your computer and use it in GitHub Desktop.
Revisions
-
simonbaird revised this gist
Jun 16, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ $ git status -s M ext/bigdecimal/lib/bigdecimal/math.rb M math.c $ /usr/local/bin/ruby --version # (after doing make && sudo make install) ruby 1.9.3dev (2011-06-16 trunk 32123) [x86_64-darwin10.7.0] $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts Math::TAU, BigMath.TAU(100)' 6.283185307179586 -
simonbaird renamed this gist
Jun 16, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
simonbaird renamed this gist
Jun 16, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
simonbaird renamed this gist
Jun 16, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
simonbaird revised this gist
Jun 16, 2011 . 2 changed files with 5 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ $ git status -s M math.c $ /usr/local/bin/ruby --version ruby 1.9.3dev (2011-06-16 trunk 32123) [x86_64-darwin10.7.0] $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts Math::TAU, BigMath.TAU(100)' 6.283185307179586 0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index c17841f..c672cbf 100644 --- a/ext/bigdecimal/lib/bigdecimal/math.rb +++ b/ext/bigdecimal/lib/bigdecimal/math.rb @@ -9,6 +9,7 @@ require 'bigdecimal' @@ -10,15 +10,13 @@ index c17841f..4463579 100644 # PI (prec) # E (prec) == exp(1.0,prec) # @@ -222,6 +223,11 @@ module BigMath y end + # See http://tauday.com/ + def TAU(prec) + PI(prec)*BigDecimal("2") + end + # Computes the value of pi to the specified number of digits of precision. -
simonbaird revised this gist
Jun 16, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ $ git status -s M ext/bigdecimal/lib/bigdecimal/math.rb M math.c $ /usr/local/bin/ruby --version ruby 1.9.3dev (2011-06-16 trunk 32123) [x86_64-darwin10.7.0] $ /usr/local/bin/ruby -e 'puts Math::TAU' 6.283185307179586 $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)' 0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1 -
simonbaird revised this gist
Jun 16, 2011 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
simonbaird revised this gist
Jun 16, 2011 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,5 +6,4 @@ ruby 1.9.3dev (2011-06-16 trunk 32123) [x86_64-darwin10.7.0] ~/git/ruby> /usr/local/bin/ruby -e 'puts Math::TAU' 6.283185307179586 ~/git/ruby> /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)' 0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1 -
simonbaird renamed this gist
Jun 16, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
simonbaird renamed this gist
Jun 16, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
simonbaird created this gist
Jun 16, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ ~/git/ruby> git status -s M ext/bigdecimal/lib/bigdecimal/math.rb M math.c ~/git/ruby> /usr/local/bin/ruby --version ruby 1.9.3dev (2011-06-16 trunk 32123) [x86_64-darwin10.7.0] ~/git/ruby> /usr/local/bin/ruby -e 'puts Math::TAU' 6.283185307179586 ~/git/ruby> /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)' 0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1 ~/git/ruby> git diff -p > ruby_tau.patch This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index c17841f..4463579 100644 --- a/ext/bigdecimal/lib/bigdecimal/math.rb +++ b/ext/bigdecimal/lib/bigdecimal/math.rb @@ -9,6 +9,7 @@ require 'bigdecimal' # atan(x, prec) Note: |x|<1, x=0.9999 may not converge. # exp (x, prec) # log (x, prec) +# TAU (prec) # PI (prec) # E (prec) == exp(1.0,prec) # @@ -222,6 +223,13 @@ module BigMath y end + # Computes the value of tau to the specified number of digits of precision. + def TAU(prec) + raise ArgumentError, "Zero or negative argument for TAU" if prec <= 0 + two = BigDecimal("2") + PI(prec)*two + end + # Computes the value of pi to the specified number of digits of precision. def PI(prec) raise ArgumentError, "Zero or negative argument for PI" if prec <= 0 diff --git a/math.c b/math.c index e3a78f7..e8b2525 100644 --- a/math.c +++ b/math.c @@ -775,8 +775,10 @@ Init_Math(void) #ifdef M_PI rb_define_const(rb_mMath, "PI", DBL2NUM(M_PI)); + rb_define_const(rb_mMath, "TAU", DBL2NUM(M_PI*2.0)); #else rb_define_const(rb_mMath, "PI", DBL2NUM(atan(1.0)*4.0)); + rb_define_const(rb_mMath, "TAU", DBL2NUM(atan(1.0)*8.0)); #endif #ifdef M_E