[Issue 23200] sqrt cast to long and ulong differ
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jun 21 15:37:21 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23200
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
--- Comment #1 from Dennis <dkorpel at live.nl> ---
Removing the Phobos dependency:
```
static import core.math;
pragma(inline, true)
double sqrt(double x) @nogc @safe pure nothrow { return core.math.sqrt(x); }
extern(C) void main()
{
double d = 9007199515875288.;
auto r1 = cast (ulong) sqrt(d);
auto r2 = cast (long) sqrt(d);
assert (r1 == r2);
}
```
It doesn't happen when calling core.math.sqrt directly, it looks like the
problem manifests because of the inliner:
```
// output of -vcg-ast
extern (C) extern (C) void main()
{
double d = 9.0072e+15;
ulong r1 = cast(ulong)((double x = d;) , sqrt(x));
long r2 = cast(long)((double x = d;) , sqrt(x));
assert(r1 == cast(ulong)r2);
return 0;
}
```
It casts the comma expression to long/ulong, which may trip up the code
generator.
--
More information about the Digitalmars-d-bugs
mailing list