Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CTFE] compile time parsing of hex floats #9934

Open
dlangBugzillaToGithub opened this issue Aug 8, 2012 · 3 comments
Open

[CTFE] compile time parsing of hex floats #9934

dlangBugzillaToGithub opened this issue Aug 8, 2012 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

ellery-newcomer reported this on 2012-08-08T12:55:19Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=8523

CC List

Description

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
@dlangBugzillaToGithub
Copy link
Author

peter.alexander.au (@Poita) commented on 2013-01-05T12:03:21Z

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.

@dlangBugzillaToGithub
Copy link
Author

clem (@legrosbuffle) commented on 2015-05-22T13:05:03Z

pull:
https://github.com/D-Programming-Language/dmd/pull/4674

@dlangBugzillaToGithub
Copy link
Author

dbugz commented on 2018-08-07T05:18:05Z

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.

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants