Issue 8523 - [CTFE] compile time parsing of hex floats
Summary: [CTFE] compile time parsing of hex floats
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: bootcamp, CTFE
Depends on:
Blocks:
 
Reported: 2012-08-08 12:55 UTC by Ellery Newcomer
Modified: 2024-12-01 16:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2012-08-08 12:55:19 UTC
doesn't work, but should.

enum string s = "0x9.D70A3D70A3D70A4p-3";
enum d2 = to!real(s);
pragma(msg, d2);

gives me:

/usr/include/dmd-d/std/conv.d(2305): Error: Cannot convert &real to long* at compile time
/usr/include/dmd-d/std/conv.d(1592):        called from here: parse(value)
/usr/include/dmd-d/std/conv.d(268):        called from here: toImpl(_param_0)
test.d(14):        called from here: to("0x9.D70A3D70A3D70A4p-3")
/usr/include/dmd-d/std/conv.d(2305): Error: Cannot convert &real to long* at compile time
/usr/include/dmd-d/std/conv.d(1592):        called from here: parse(value)
/usr/include/dmd-d/std/conv.d(268):        called from here: toImpl(_param_0)
test.d(15):        called from here: to("0x9.D70A3D70A3D70A4p-3")
to("0x9.D70A3D70A3D70A4p-3")

however,

double d = to!real(s);
writeln(d);

compiles and prints

1.23
Comment 1 Peter Alexander 2013-01-05 12:03:21 UTC
Added CTFE tag. I don't think there's any sane way to do this without CTFE support for the pointer cast, or at least unions.
Comment 2 Clement Courbet 2015-05-22 13:05:03 UTC
pull:
https://github.com/D-Programming-Language/dmd/pull/4674
Comment 3 Joakim 2018-08-07 05:18:05 UTC
Got rid of all the hex bit-packing in `std.conv.parse`, only missing bit is the call to C's `ldexp`, which still causes this to fail at compile-time. You can replace that with manual exponentiation if wanted to fix this, just as done for decimal strings now.
Comment 4 dlangBugzillaToGithub 2024-12-01 16:15:28 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9934

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB