Bug 21 – unexpected results for: double -> real with value 1.7976931348623157e+308

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-03-06T11:11:00Z
Last change time
2014-02-14T20:33:27Z
Assigned to
bugzilla
Creator
thomas-dloop

Comments

Comment #0 by thomas-dloop — 2006-03-06T11:11:06Z
Porting from C to D. == test.c == # #include <assert.h> # # int main(){ # double d = 1.7976931348623157e+308; # long double ld = d; # # assert(ld == 1.7976931348623157e+308); # # return 0; # } == test.d == # int main(){ # double d = 1.7976931348623157e+308; # real ld = d; # # assert(ld == 1.7976931348623157e+308); # # return 0; # } test results: ==C code (64 bit mode)== [PASS] double: 0xFFFFFFFFFFFFEF7F long double: 0x00F8FFFFFFFFFFFFFE43400000000000 ==C code (32 bit mode)== [PASS] double: 0xFFFFFFFFFFFFEF7F long double: 0x00F8FFFFFFFFFFFFFE43FFFF ==D code (32 bit mode)== [FAIL] double: 0xFFFFFFFFFFFFEF7F real: 0x00F8FFFFFFFFFFFFFE430000 test cases: http://dstress.kuehne.cn/run/d/double_28_A.d http://dstress.kuehne.cn/run/d/double_28_B.d
Comment #1 by bugzilla — 2006-03-06T14:06:31Z
This is not a bug. D always tries to do any compile time evaluation of floating point constants at max precision. So, you can get different results by assigning the same literal to a double than if it is assigned to a real. The assignment to double rounds the literal to double precision, the assignment to real rounds it to real precision.