Bug in std::floor?

Andrew Haley aph@redhat.com
Tue Nov 14 17:40:00 GMT 2017

On 14/11/17 13:29, Jonathan Wakely wrote:
> On 13 November 2017 at 11:42, Andrew Haley wrote:
>> On 13/11/17 10:38, Mason wrote:
>>> On 09/11/2017 16:46, Vincent Lefevre wrote:
>>>> Actually, that's mainly a language design bug, which doesn't show
>>>> the error for 460 (which is representable exactly).
>>> It's not clear to me exactly /what/ you are calling a language design bug?
>>> And in what language? C? IEEE 754?> (AFAIK, C is pretty loose with the floating point spec.)
>> This is C++.  The problem is that std::cout << v doesn't print all of
>> the digits in v: ideally, it'd print the minimum number of digits such
>> that reading the number back would result in a double equal to v.
> It might be nice to have that as an option (maybe via an I/O
> manipulator like std::fixed) but even if it wasn't too late to change
> the default behaviour, most people probably want 1.1 to be printed as
> 1.1 even though it's really something different.

1.1 would still print as 1.1.  4.6 * 100 would print as
459.99999999999994, because that's the truth.

Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the Gcc-help mailing list