wth!! ctfe cannot format floating point at compile time?
Johnson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 13 21:29:17 PDT 2017
On Monday, 14 August 2017 at 03:52:40 UTC, HypperParrow wrote:
> On Monday, 14 August 2017 at 01:52:16 UTC, Johnson Jones wrote:
>> Error: uncaught CTFE exception
>> std.format.FormatException("Cannot format floating point types
>> at compile-time")
>> called from here: to(0.75)
>>
>> 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?
>
> There is this trick as workaround:
>
> ```
> auto valueToString(alias v)(){return v.stringof;}
> enum a = valueToString!(0.75);
> static assert(a == "0.75");
> ```
>
> The problem with to() and format() is that is requires external
> library calls that are not available at compile-time, just like
> when you try to use malloc() at CT.
Thanks! You'd think that to would do this internally
automatically ;/
More information about the Digitalmars-d-learn
mailing list