Overly clever constant folding

John Colvin john.loughran.colvin at gmail.com
Sat Dec 10 21:36:42 UTC 2022


Is this the "constant fold at higher precision and break all your 
IEEE-754 expectations" madness again? Or something else?

```
void main()
{
     auto a = long.min;
     auto b = long.max;
     auto c = 0.0;
     writeln((long.min + long.max) + 0.0); // -1
     writeln(long.min + (long.max + 0.0)); // -1
     writeln(long.min + cast(double)(long.max)); // -1
     writeln((a + b) + c); // -1
     writeln(a + (b + c)); // 0
     writeln(a + cast(double)(b)); // 0
}
```

Hint for those confused: the nearest double to long.max is one 
greater than long.max

The 3rd one is particularly awful.


More information about the Digitalmars-d mailing list