The following:
import std.stdio;
const float f = 0.2f;
void main()
{
writeln(f - 0.2);
}
prints 0, but it should print 2.98023e-09
Comment #1 by ibuclaw — 2022-02-05T23:33:22Z
The introduction of `core.math.toPrec' was made to specifically handle this case, as compile-time floats are stored at full precision.
Comment #2 by dlang-bot — 2022-02-06T01:04:45Z
@WalterBright created dlang/dmd pull request #13613 "fix Issue 22740 - float and double literals should be rounded to theiā¦" fixing this issue:
- fix Issue 22740 - float and double literals should be rounded to their precision
https://github.com/dlang/dmd/pull/13613
Comment #3 by robert.schadek — 2024-12-13T19:20:47Z