a way to specily floating-point numbers as bit patters

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 9 09:34:28 PDT 2017


Honey wrote:

> On Friday, 9 June 2017 at 16:07:36 UTC, ketmar wrote:
>> one of my calculated values is `-0.166667`, which has bit-pattern of 
>> 0xBE2AAAB7.
>> now, let's say i want to use this number in my code:
>>
>> 	float v = -0.166667f;
>> 	writefln("%f 0x%08X", v, *cast(uint*)&v);
>>
>> oooops. "-0.166667 0xBE2AAAC1". it's not the same! (and yes, it matters).
>
> Try -0.16666685f.

it doesn't matter if i can find the decimal representation for the given 
bit pattern or not. the whole post is about removing the need to rely on 
lossy binary->decimal->binary conversions.


More information about the Digitalmars-d-learn mailing list