Date: Sun, 25 Aug 2024 11:45:13 -0400
> On Aug 25, 2024, at 8:10 AM, Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 8/25/24 14:08, Mike Reed via Std-Proposals wrote:
>> 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.
>
> You're thinking in decimal. IEEE-754 binary floating point types
> representation, which is used practically by every C++ implementation,
> uses powers of two for its digit places.
IEEE-754 also defines decimal floating point (DFP). C23 includes DFP support and I expect we’ll see DFP support added to the C++ standard at some point. Gcc supports DFP types.
So, yes, in a future C++ standard,
`2*std::numbers::pi_v<std::decimal32>` could produce a different value than `std::numbers::tau_v<std::decimal32>` would, depending on rounding mode.
Tom.
> That is, the significand is
> represented by a binary mantissa, and the point placement within that
> mantissa is described by exponent. Multiplying or dividing the number by
> a power of two leaves the mantissa unchanged and only changes the
> exponent. This means that the precision of the number remains the same.
> At least, that's how an implementation is expected to behave.
>
> https://en.wikipedia.org/wiki/IEEE_754
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> On 8/25/24 14:08, Mike Reed via Std-Proposals wrote:
>> 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.
>
> You're thinking in decimal. IEEE-754 binary floating point types
> representation, which is used practically by every C++ implementation,
> uses powers of two for its digit places.
IEEE-754 also defines decimal floating point (DFP). C23 includes DFP support and I expect we’ll see DFP support added to the C++ standard at some point. Gcc supports DFP types.
So, yes, in a future C++ standard,
`2*std::numbers::pi_v<std::decimal32>` could produce a different value than `std::numbers::tau_v<std::decimal32>` would, depending on rounding mode.
Tom.
> That is, the significand is
> represented by a binary mantissa, and the point placement within that
> mantissa is described by exponent. Multiplying or dividing the number by
> a power of two leaves the mantissa unchanged and only changes the
> exponent. This means that the precision of the number remains the same.
> At least, that's how an implementation is expected to behave.
>
> https://en.wikipedia.org/wiki/IEEE_754
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-08-25 15:45:25