For various reasons I am using IEEE754 32-floating point numbers such as:
‘the closest value to 2 less than 2’ - represented by the bit pattern 0x3fffffff,
‘the value just below 1/root(2)’ - represented by the bit pattern: 0x3f3504f3
and other constants. Im using C++ in VS2019, and Id like to have the HLSL operator ‘asfloat’ and say something like:
const float belowTwo = asfloat(0x3fffffff);
Of course I could do the horrible:
unsigned int gumf = 0x3fffffff; float belowTwo = *(float *)&gumf;
But I would have to get rid of the constness. And this is just…. nasty….
The only other way I could do in VS2019 is to use the c++17 floating point constant format that was added, and do something like:
const float oneOverRootTwo = 0xb504f3.0p-24; // bit pattern: 0x3f3504f3 = just below 1/root(2)
And write a simple utility to generate the constant code. Which is what I am currently using,
So… is there any way to enter floating point constants as bit patterns directly ? - I understand that it could be argued that the underlying implementation of float is not the language… so they might avoind supporting it, but it just makes things messy when it is needed,,,,
Cheers