Basile B. wrote:

oooops. "-0.166667 0xBE2AAAC1". it's not the same! (and yes, it matters).

-0.166667f is not representable as a 32 bit float. The actuall value that's stored is -0.16666699945926666259765625, hence the difference. See https://www.h-schmidt.net/FloatConverter/IEEE754.html and enter your value in the field labeled "You entered".

i'm completely aware about floating point values representation, and problems with bin->dec->bin conversions of floats. the post is about avoiding those conversions at all.

and this means that i can't inline my calculated values! each time i want to get floating value with a known bit-pattern, i have to store it as uint, and resort to ugly hack: `*cast(immutable(float)*)(&mytable[2])`.

and i can't do this trick in CTFE, as such pointer tricks aren't permitted.

i tried different workarounds, but they're all ugly. it would be very nice to have a way to define IEEE floating point numbers as bit-patterns in the language itself. what do you think?

Yes, easy to do, a template alĂ  octal or hexString.

can you show it, please? remember, CTFE-able!

Reply via email to