Bug 5280 – to!FP(Hex float string) doesn't work well
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-11-26T15:09:00Z
Last change time
2013-12-09T12:22:37Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-11-26T15:09:33Z
This code seems correct:
import std.conv: to;
void main() {
real r0 = 0x1.0076fc5cc7933866p+40L; // OK
auto r = to!real("0x1.0076fc5cc7933866p+40L");
auto d = to!double("0x1.0076fc5cc7933866p+40L");
auto f = to!float("0x1.0076fc5cc7933866p+40L");
}
But DMD 2.050 returns:
std.conv.ConvError: std.conv(723): Can't convert value `L' of type const(char)[] to type real
Comment #1 by hsteoh — 2013-12-09T12:00:39Z
This bug seems to have changed since the past 3 years. Now the code prints this error at runtime:
std.conv.ConvException@/usr/src/d/phobos/std/conv.d(1804): Unexpected 'L' when converting from type string to type real
Removing the trailing 'L' from the input strings makes the conversion work successfully for all 3 floating types.
I'm not sure if this should still be considered a bug, since technically the 'L' is specific to D's literal syntax, and shouldn't be part of a general floating-point parsing format? Or should std.conv be changed to understand the 'L'? (Seems a bit pointless, since the template argument to to() already tells whether the literal is intended to be long or not.)
Comment #2 by bearophile_hugs — 2013-12-09T12:22:37Z