Date: Sun, 25 Aug 2024 19:49:31 +0000 (UTC)
Re: Mike Reed <mike_at_[hidden]>:
> Isn't it possible for a literal constant for tau to be more accurate than
> 2x a literal constant for pi? E.g if my architecture is only accurate to
> 1dp then the literal for pi is 3.1, and 2x that is 6.2. But the literal
> constant for tau would be 6.3, which is more accurate.
In the specific case of binary floating point and multiplication by 2, no. It would be the same as decimal floating point and multiplication by 10. For example, 1.234 * 10 is exactly 12.34. However, technically, I don't think the C++ standard *requires* float/double to be binary floating-point - though it *is* binary floating-point literally everywhere as the "de facto" rule even if it's not "de jure".
Re: Tiago Freire <tmiguelf_at_[hidden]>:
> I'm very much convinced at this point that the argument for the
> introduction of tau is one of convenience rather than precision over 2*pi.
Yes, my argument was never about precision. It was always about convenience, readability, and code correctness, such as preventing the mistake of using `2 * pi` instead of the correct `(2 * pi)` or `tau`.
This is the same argument for having the <numbers> header at all, because you can always write out the literal value in full precision for any of those constants instead of using the one in <numbers>, but using the constant in <numbers> increases readability. The circle constant (2*pi or simply tau) is very common, arguably the most common irrational constant, more common than pi by itself, and much more common than some other values already in <numbers> such as egamma.
However, as Tom Honermann <tom_at_[hidden]> mentions, there may be a precision difference when using decimal float types. It would be unfortunate if the most common constant is inaccurate by one ULP in decimal. This is not my argument, but it may be additional justification.
> Isn't it possible for a literal constant for tau to be more accurate than
> 2x a literal constant for pi? E.g if my architecture is only accurate to
> 1dp then the literal for pi is 3.1, and 2x that is 6.2. But the literal
> constant for tau would be 6.3, which is more accurate.
In the specific case of binary floating point and multiplication by 2, no. It would be the same as decimal floating point and multiplication by 10. For example, 1.234 * 10 is exactly 12.34. However, technically, I don't think the C++ standard *requires* float/double to be binary floating-point - though it *is* binary floating-point literally everywhere as the "de facto" rule even if it's not "de jure".
Re: Tiago Freire <tmiguelf_at_[hidden]>:
> I'm very much convinced at this point that the argument for the
> introduction of tau is one of convenience rather than precision over 2*pi.
Yes, my argument was never about precision. It was always about convenience, readability, and code correctness, such as preventing the mistake of using `2 * pi` instead of the correct `(2 * pi)` or `tau`.
This is the same argument for having the <numbers> header at all, because you can always write out the literal value in full precision for any of those constants instead of using the one in <numbers>, but using the constant in <numbers> increases readability. The circle constant (2*pi or simply tau) is very common, arguably the most common irrational constant, more common than pi by itself, and much more common than some other values already in <numbers> such as egamma.
However, as Tom Honermann <tom_at_[hidden]> mentions, there may be a precision difference when using decimal float types. It would be unfortunate if the most common constant is inaccurate by one ULP in decimal. This is not my argument, but it may be additional justification.
Received on 2024-08-25 19:51:34