Bug of the sqrt() compiled by DMD

jmh530 john.michael.hall at gmail.com
Sun Jun 19 22:45:48 UTC 2022


On Sunday, 19 June 2022 at 08:36:33 UTC, Salih Dincer wrote:
> [snip]

Not sure why the discrepancy between ulongs and longs since the 
maximum ulong and long should be below n^2, but the issue with 
doubles is exactly as others described: 94,906,267^2 can't be 
represented exactly as a double.

```
import std.stdio;

void main()
{
     ulong n_ulong = 94_906_267;
     double n_ulong2 = n_ulong * n_ulong;
     long n_ulong3 = n_ulong * n_ulong;
     ulong n_ulong4 = n_ulong * n_ulong;
     writefln!("%f")(n_ulong2);
     writefln!("%f")(n_ulong3);
     writefln!("%f")(n_ulong4);

     long n_long = 94_906_267;
     double n_long2 = n_long * n_long;
     long n_long3 = n_long * n_long;
     ulong n_long4 = n_long * n_long;
     writefln!("%f")(n_long2);
     writefln!("%f")(n_long3);
     writefln!("%f")(n_long4);
}
```



More information about the Digitalmars-d mailing list