[ create a new paste ] login | about

Link: http://codepad.org/nUJyk6fH    [ raw code | output | fork ]

C, pasted on Feb 10:
#include <stdio.h>
#include <stdlib.h>

typedef float         f32;
typedef unsigned int  u32;

f32 h2f(u32 value)
{
	f32* f = (f32*)&value;
	return *f;
}

u32 f2i(f32 value)
{
	u32* i = (u32*)&value;
	return *i;
}

int main(int argc, char ** argv)
{
	f32 f1 = 1.0;
	f32 f2 = 2.0;
	f32 f3 = 2.5;
	f32 f4 = 5.0;
	printf("0x%08x\n", f2i(f1 + f1 + f1 + f2));
	printf("0x%08x\n", f2i(f4));
	printf("%f\n", h2f(0x3f800000));
	return EXIT_SUCCESS;
}


Output:
1
2
3
0x40a00000
0x40a00000
1.000000


Create a new paste based on this one


Comments: