diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index 16cf9c8..7b43cca 100644 --- a/ext/bigdecimal/lib/bigdecimal/math.rb +++ b/ext/bigdecimal/lib/bigdecimal/math.rb @@ -7,6 +7,7 @@ require 'bigdecimal' # sin (x, prec) # cos (x, prec) # atan(x, prec) Note: |x|<1, x=0.9999 may not converge. +# TAU (prec) # PI (prec) # E (prec) == exp(1.0,prec) # @@ -144,6 +145,12 @@ module BigMath y end + # See http://tauday.com/ + def TAU(prec) + raise ArgumentError, "Zero or negative argument for TAU" if prec <= 0 + 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 96bd1e9..cc2207b 100644 --- a/math.c +++ b/math.c @@ -782,8 +782,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