Last active
December 24, 2015 18:09
-
-
Save nurpax/6840820 to your computer and use it in GitHub Desktop.
unsigned int to float
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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