Re: Mapping float to ulong in CTFE

2019-12-13 Thread berni44 via Digitalmars-d-learn
Yeah, it worked (at least for %a): static assert(format!"%.3a"(1.0f) == "0x1.000p+0");

Re: Mapping float to ulong in CTFE

2019-12-13 Thread berni44 via Digitalmars-d-learn
On Thursday, 12 December 2019 at 19:39:16 UTC, Petar Kirov [ZombineDev] wrote: You can use a C-style pointer reinterpret cast like this: uint test(float f) { return *cast(uint*)&f; } Make sure that source and destination types have the same size. Hey, great! :-)

Re: Mapping float to ulong in CTFE

2019-12-12 Thread Petar via Digitalmars-d-learn
On Thursday, 12 December 2019 at 19:21:22 UTC, berni44 wrote: Is it possible to get to the bits of a float in CTFE? I tried the following, but this doesn't work: ``` import std.stdio; union FloatBits { float floatValue; ulong ulongValue; } ulong test(float f) { FloatBits fb; f

Mapping float to ulong in CTFE

2019-12-12 Thread berni44 via Digitalmars-d-learn
Is it possible to get to the bits of a float in CTFE? I tried the following, but this doesn't work: ``` import std.stdio; union FloatBits { float floatValue; ulong ulongValue; } ulong test(float f) { FloatBits fb; fb.floatValue = f; return fb.ulongValue; } void main() {