Issue #4897 has been updated by drbrain (Eric Hodel).


=begin

Despite all the argument for this constant, nobody has provided a patch, so it seems like a joke.

Runtime performance of a constant lookup is 3% +/- 1.2% faster than multiplying a float by 2 on my machine over 20 million multiplications.  3% for a built-in constant doesn't seem like a big deal.

I don't trust a wikipedia user page as a reference, it doesn't go through the same vetting process as a regular wikipedia page.

Benchmarks:

  $ cat bm.rb 
  require 'benchmark'
  
  module Math
    TAU = 2*Math::PI
  end
  
  range = Float::EPSILON..10.0
  
  N = Integer ARGV.shift
  
  case ARGV.shift
  when 'tau' then
    puts Benchmark.measure {
      N.times do
        2 * Math::PI * rand(range)
      end
    }.real
  when '2pi' then
    puts Benchmark.measure {
      N.times do
        2 * Math::TAU * rand(range)
      end
    }.real
  else
    abort "#{$0} N tau|2pi"
  end
  $ for i in `jot 20`; do ruby bm.rb 1_000_000 2pi; done > 2pi.txt
  $ for i in `jot 20`; do ruby bm.rb 1_000_000 tau; done > tau.txt
  $ ministat tau.txt 2pi.txt 
  x tau.txt
  + 2pi.txt
  +------------------------------------------------------------------------------+
  |x    xx    x    +   +     +    +      +                                       |
  |x x x*xxx+ x * x+   * ++x +++  +     ++        +                             +|
  | |____M_A___|_|___________MA_______________|                                  |
  +------------------------------------------------------------------------------+
      N           Min           Max        Median           Avg        Stddev
  x  20      0.486589      0.504393      0.491397    0.49242015  0.0049904288
  +  20      0.490699      0.544828      0.506571     0.5073239   0.011828075
  Difference at 95.0% confidence
  	0.0149037 +/- 0.00581011
  	3.02663% +/- 1.17991%
  	(Student's t, pooled s = 0.00907766)  

=end
----------------------------------------
Feature #4897: Define Math::TAU and BigMath.TAU. The "true" circle constant, Tau=2*Pi. See http://tauday.com/
https://bugs.ruby-lang.org/issues/4897#change-37132

Author: sbaird (Simon Baird)
Status: Feedback
Priority: Low
Assignee: 
Category: Joke
Target version: Next Major


Firstly please read the Tau Manifesto at http://tauday.com/ . It's quite long but essential to understanding why this is a good idea.

Here is a patch on trunk that implements this:
http://simonbaird.blogspot.com/2011/06/tau-in-ruby.html

Allow me to anticipate and respond in advance to some common objections:

1. It's easy to define it yourself so why put this in core.
Possibly correct, but I think this is the right thing to do. Tau is important. And it's a pretty small patch.

2. If this constant goes in then pretty soon someone will want every other math constant and there are hundreds of them. (Slippery slope argument).
The circle constant is one of the two most important numbers is mathematics. It's not just another math constant. We already define Pi.


-- 
http://bugs.ruby-lang.org/