RFR: JDK-8283124: Add constant for tau to Math and StrictMath

Kevin Bourrillion kevinb at google.com
Tue Mar 15 14:09:06 UTC 2022


I did a subjective eval of 30 random usages of Math.PI in our codebase. I
would repeat this in more detail if it were seen as useful.

These usages really wanted --

* Math.toRadians (6)
* Math.TAU (10) [usually, they are explicitly doubling it]
* Math.PI (1) [some high-pass filter formula uses a bare pi]
* subject to taste (13)

By the last one, I mean that the more a person has read, understood, and
agreed with the Tau Manifesto the more they would prefer to use TAU in that
situation. For example, for code that's talking about rotating an image a
"quarter-turn", or the angle measure in a rectangle, TAU / 4 is very
natural. But what about clamping a longitude expressed in radians -- is it
cleaner to think that the absolute value is less than (a) one halfturn (PI)
or (b) one-half of a turn (TAU/2)? Who can say.

I suppose that introducing a new cause for subjective arguments between
teammates is no a small thing. But still, the 10-to-1 part sells it for me.
Again, I could flesh this out if necessary.

(On a side note, the real-world value for "they should just use
to/fromRadians" will be *much* higher than this. We actually have static
analyzers that have been trying to nag people into using those methods for
years, so these 6/30 are just the ones we didn't catch.)


On Mon, Mar 14, 2022 at 6:23 PM Kevin Bourrillion <kevinb at google.com> wrote:

> On Mon, Mar 14, 2022 at 4:16 PM Joe Darcy <darcy at openjdk.java.net> wrote:
>
> Yes; after further thought, I agree having tau = 2.0*pi is preferable.
>>
>
> Kinda reads like it's taking a stand on which of the two is the *real*
> fundamental mathematical constant and which one is a hack. Therefore it
> should really be pi that's set to tau/2.0 :-)
>
> Can PI have a @see link to this so that people know about it?
>
> (I'll just mention that {from,to}Radians would also benefit from some
> advertisement, as a great many PI usages are dividing it by or into 180,
> but do what thou wilt with that FYI.)
>
>
> --
> Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
>


-- 
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com


More information about the core-libs-dev mailing list