wth!! ctfe cannot format floating point at compile time?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 13 20:44:27 PDT 2017


On Monday, 14 August 2017 at 01:52:16 UTC, Johnson Jones wrote:
> pretty simply, trying to convert a floating point to a string 
> in a ctfe function and it thinks that it is too complex to do 
> in a ctfe, really?

It uses a C function to do the conversion, which is not available 
at compile time since CTFE can't run extern functions.

And it is a LOT harder to do than you might think which is why it 
still uses the C function - implementing one in D is legit pretty 
complex.

When I first saw this too, I figured it must be simple to slap 
something together, even if it is horribly inefficient and 
doesn't work everywhere... and I ended up giving up after 
spending a few hours on it too. If you search the web, you get 
academic papers describing it, eeek.

Of course, it might be reasonable to port one of the C 
implementations directly... but even that is a fairly big job 
(and you might as well just call the C function itself for all 
but CTFE cases) - the GNU one is 1,300 lines, for example. And 
that has an incompatible license with the rest of druntime!


More information about the Digitalmars-d-learn mailing list