Overly clever constant folding

Iain Buclaw ibuclaw at gdcproject.org
Sun Dec 11 14:13:41 UTC 2022


On Saturday, 10 December 2022 at 21:36:42 UTC, John Colvin wrote:
> Is this the "constant fold at higher precision and break all 
> your IEEE-754 expectations" madness again? Or something else?
>
--snip--
>
> Hint for those confused: the nearest double to long.max is one 
> greater than long.max
>
> The 3rd one is particularly awful.

This is exactly what core.math.toPrec was made for.
```
import core.math;
writeln((long.min + long.max) + 0.0); // -1
writeln(long.min + toPrec!double(long.max + 0.0)); // 0
writeln(long.min + toPrec!double(long.max)); //  0
```



More information about the Digitalmars-d mailing list