a way to specily floating-point numbers as bit patters

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 9 10:23:01 PDT 2017


Basile B. wrote:

> On Friday, 9 June 2017 at 17:18:43 UTC, ketmar wrote:
>> Basile B. wrote:
>>
>>>      enum binFloat = *cast(float*) &b;
>>
>> i was SO sure that this won't work in CTFE that i didn't even tried to 
>> do it. "it will fail anyway, there is no reason in trying!" ;-)
>
> You can do the arithmetic as well. I don't know why but i supposed that 
> my static asserts were a proof of CTFE-ability.

yeah, it is CTFEable. now i recall that such casting for floats was 
special-cased in interpreter exactly to allow this kind of things. my bad.


More information about the Digitalmars-d-learn mailing list