The function l2f turns an int into a float with the same bit pattern. The function f2l turns a float into an int with the same bit pattern. This is a different result than you get with a cast: l2f(x) != (float)x .
float l2f(int l)
/* convert long integer to float with same bit pattern */
{
union {
float f;
int ll;
} a;
a.ll = l;
return a.f;
}
int f2l(float f)
/* convert float to long integer with same bit pattern */
{
union {
float ff;
int l;
} a;
a.ff = f;
return a.l;
}


Sign In
Create Account


Back to top









