D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17185 - Error: number '0x0.0123p-1022' is not representable
Summary: Error: number '0x0.0123p-1022' is not representable
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-15 17:07 UTC by Sophie
Modified: 2022-11-16 14:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Sophie 2017-02-15 17:07:40 UTC
I had a line of code including `double(0x0.0123p-1022)` which compiled fine on Windows 7 and OSX; note that 0x0.0123p-1022 is representable as a subnormal double. When compiling on linux with dmd v2.073.0 I received a compile error "Error: number '0x0.0123p-1022' is not representable" - which is not correct, because it is representable as a subnormal.

It is possible to write `double(0x0.0123p-1022L)` instead as a workaround.

Parsing subnormal reals e.g. 0x0.0123p-16382L seems to work fine on all three platforms.
Comment 1 Sophie 2017-02-15 18:04:15 UTC
This occurred when compiling on ubuntu 12.04.04
Comment 2 Stefan Koch 2017-02-15 19:21:39 UTC
This occurs because dmd's parser calls strtold from the c runtime to parse floats.
apparently ubuntu 12.04 version of the runtime does mess this up.
Comment 3 Sophie 2017-02-15 20:40:27 UTC
Note that one possible solution to this bug would be to use a custom strtold implementation rather than relying on the runtime. For reference, here is one such function implemented in native D code: https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric/hexfloats.d#L147
Comment 4 RazvanN 2022-11-16 14:47:34 UTC
This code:

void main()
{
    import std.stdio : writeln;
    writeln(double(0x0.0123p-1022)); // Prints 64+64i, should print 64+0i                                                                                       
}


compiles just fine on my machine (Ubunutu 20.04.4).