On Mon, 14 Mar 2022 20:52:39 GMT, Joe Darcy <da...@openjdk.org> wrote:
> Add a constant for tau, 2*pi, to Math and StrictMath. Since 2*pi is a very > common value in mathematical formulas, it is helpful to give it a distinct > constant. > > Please also review the CSR https://bugs.openjdk.java.net/browse/JDK-8283136 > _Mailing list message from [Hans Boehm](mailto:hbo...@google.com) on > [core-libs-dev](mailto:core-libs-...@mail.openjdk.java.net):_ > > Couldn't the apiNote just say TAU == 2 * PI instead? I think the fact that > this is actually a guaranteed floating point equality aids clarity. > > On Mon, Mar 14, 2022 at 2:33 PM Raffaello Giulietti < raffaello.giulietti at > gmail.com> wrote: > > > Hello, > > I find it a bit disturbing that PI is specified with 21 digits whereas > > TAU has 16. > > I think that specifying PI as > > public static final double PI = 3.141592653589793; > > doesn't harm anybody and makes it visually more consistent with TAU- > > Greetings > > Raffaello > > On 3/14/22 22:13, Brian Burkhalter wrote: > > > On Mon, 14 Mar 2022 20:52:39 GMT, Joe Darcy <darcy at openjdk.org> wrote: > > > > Add a constant for tau, 2*pi, to Math and StrictMath. Since 2*pi is a > > > > very common value in mathematical formulas, it is helpful to give it a > > > > distinct constant. > > > > Please also review the CSR > > > > https://bugs.openjdk.java.net/browse/JDK-8283136 Yes; after further thought, I agree having tau = 2.0*pi is preferable. Just to go through the logic, 2.0 is exactly representable in binary floating-point and an in-range multiple by two is just an exponent adjustment. Floating-point exponent transitions occur at 2.0 = 0x1 * 2^1, 4.0 = 0x1 * 2^2, and 8.0 = 0x1 * 2^3. The value of pi is between 2.0 and 4.0 and has an exponent of 1 while the value of tau ~= 6.28 is between 4.0 and 8.0 and has an exponent of 2. So whatever the closest floating-point value to exact pi is, 2.0 * Math.pi will be the closest floating-point value to tau. ------------- PR: https://git.openjdk.java.net/jdk/pull/7813