Patch ruby to define tau
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 |
$ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment