public
Created

Patch ruby to define tau

  • Download Gist
tau.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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'
# 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,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.
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
zzdemo
1 2 3 4 5 6 7 8
$ 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
0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.