Skip to content

Instantly share code, notes, and snippets.

@simonbaird
Created June 16, 2011 15:51
Show Gist options
  • Save simonbaird/1029552 to your computer and use it in GitHub Desktop.
Save simonbaird/1029552 to your computer and use it in GitHub Desktop.

Revisions

  1. simonbaird revised this gist Jun 16, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zzdemo
    Original 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
    $ /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
  2. simonbaird renamed this gist Jun 16, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. simonbaird renamed this gist Jun 16, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. simonbaird renamed this gist Jun 16, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. simonbaird revised this gist Jun 16, 2011. 2 changed files with 5 additions and 8 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.txt → demo
    Original 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 -e 'puts Math::TAU'
    $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts Math::TAU, BigMath.TAU(100)'
    6.283185307179586
    $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)'
    0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1
    10 changes: 4 additions & 6 deletions gistfile2.diff → patch
    Original 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..4463579 100644
    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,13 @@ module BigMath
    @@ -222,6 +223,11 @@ module BigMath
    y
    end

    + # Computes the value of tau to the specified number of digits of precision.
    + # See http://tauday.com/
    + def TAU(prec)
    + raise ArgumentError, "Zero or negative argument for TAU" if prec <= 0
    + two = BigDecimal("2")
    + PI(prec)*two
    + PI(prec)*BigDecimal("2")
    + end
    +
    # Computes the value of pi to the specified number of digits of precision.
  6. simonbaird revised this gist Jun 16, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    ~/git/ruby> git status -s
    $ git status -s
    M ext/bigdecimal/lib/bigdecimal/math.rb
    M math.c
    ~/git/ruby> /usr/local/bin/ruby --version
    $ /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'
    $ /usr/local/bin/ruby -e 'puts Math::TAU'
    6.283185307179586
    ~/git/ruby> /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)'
    $ /usr/local/bin/ruby -r bigdecimal/math -e 'puts BigMath.TAU(100)'
    0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1
  7. simonbaird revised this gist Jun 16, 2011. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  8. simonbaird revised this gist Jun 16, 2011. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions demo
    Original 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
    ~/git/ruby> git diff -p > ruby_tau.patch
    0.62831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646057277261767213856E1
  9. simonbaird renamed this gist Jun 16, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. simonbaird renamed this gist Jun 16, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. simonbaird created this gist Jun 16, 2011.
    10 changes: 10 additions & 0 deletions Example
    Original 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
    41 changes: 41 additions & 0 deletions ruby_tau.patch
    Original 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