Skip to content

Instantly share code, notes, and snippets.

@nurpax
Last active December 24, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurpax/6840820 to your computer and use it in GitHub Desktop.
Save nurpax/6840820 to your computer and use it in GitHub Desktop.
unsigned int to float
#include <stdio.h>
static inline float uintToFloat(unsigned int v)
{
union {
unsigned int ui;
float f;
} c;
c.ui = v;
return c.f;
}
static const float foox = uintToFloat(0x3f800000);
class Foo
{
public:
static const float ONE;
};
const float Foo::ONE = uintToFloat(0x3f800000);
int main(void)
{
static const float foo = uintToFloat(0x3f800000);
printf("%f %f\n", foox, foo);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment