Issue 22740 - float and double literals should be rounded to their precision
Summary: float and double literals should be rounded to their precision
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-02-05 23:15 UTC by Walter Bright
Modified: 2022-12-17 10:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2022-02-05 23:15:15 UTC
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 Iain Buclaw 2022-02-05 23:33:22 UTC
The introduction of `core.math.toPrec' was made to specifically handle this case, as compile-time floats are stored at full precision.
Comment 2 Dlang Bot 2022-02-06 01:04:45 UTC
@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