Double literal 4.9E-324 produces error in dmd/ldc2 for mac, while it compiles on windows or even on wine without any issue.
Also double.min seems to not be defined, while double.max is. https://dlang.org/ctod.html double.min appears in this page, so in the case it is not defined it should be removed as example in that page.
D doubles are IEEE 754 right? https://dlang.org/d-floating-point.html
At least literals should work consistently among platforms?
Since I'm generating double literals automatically I need a reliable way to represent doubles that compile on every platform D supports. So what should I do?
Something like this?
if (doubleValue >= 0.0 && doubleValue <= 4.940656e-324) "4.940656e-324" else "$doubleValue"
since double.min is not defined I can't do this:
if (doubleValue >= 0.0 && doubleValue <= 4.940656e-324) "double.min" else "$doubleValue"
DMD version (in both cases): v2.072.0
ldc2 --version
LDC - the LLVM D compiler (3461e0):
based on DMD v2.070.2 and LLVM 3.9.0
Fails on MacOSX:
➜ jtransc-d git:(master) ✗ dmd test.d
test.d(15): Error: number '4.9E-324' is not representable
➜ jtransc-d git:(master) ✗ ldc2 test.d
test.d(15): Error: number '4.9E-324' is not representable
Works on Windows + wine:
➜ jtransc-d git:(master) ✗ wine cmd
dmd testMicrosoft Windows 5.1.2600 (1.8.5)
Z:\Users\soywiz\Projects\jtransc-examples\hello-world\build\jtransc-d>dmd test.d
Z:\Users\soywiz\Projects\jtransc-examples\hello-world\build\jtransc-d>exit
// Tested code:
import std.stdio;
int main() {
// long v = 1L;
double a = double.max;
// double a = double.min;
writefln("%e", a);
/*
http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#MIN_VALUE
MIN_VALUE
public static final double MIN_VALUE
A constant holding the smallest positive nonzero value of type double, 2-1074. It is equal to the hexadecimal floating-point literal 0x0.0000000000001P-1022 and also equa$
*/
long v = 1L;
double b = 4.9E-324;
//align(8) long v = 0x7ff8000000000000L;
//long v = 0x0010000000000000L;
// double b = *cast(double*)&v;
writefln("%e", b);
return 0;
}
Comment #1 by robert.schadek — 2024-12-13T18:50:50Z