Floating Point Examples
/* floats.exmp Print out floating point numbers 06 Feb 91 */ static float nums[30] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 3.1, 3.14, 3.1415927, 0.5, 0.25, 0.125, -1.0, -2.0, -3.0, -0.5, -0.25, -3.1415927 }; printnum(f,plainf) float f; unsigned plainf; /* look at the float as a bit string */ { int sign, exp, expb; long mant, mantb; { sign = (plainf >> 31) & 1; exp = (plainf >> 20) & 2047; expb = exp - 1023; mant = plainf & 1048575; mantb = mant + 1048576; printf("%12f %11o %1o %4o %5d %7o %7o\n", f, plainf, sign, exp, expb, mant, mantb); } } /* This appears to be double-precision floating point format: */ /* 1 bit sign, 11 bits biased exponent, 20 bits mantissa + 32 in next word */ floating octal sign biased corrected actual corrected exponent exponent mantissa mantissa 0.000000 0 0 0 -1023 0 4000000 1.000000 7774000000 0 1777 0 0 4000000 2.000000 10000000000 0 2000 1 0 4000000 3.000000 10002000000 0 2000 1 2000000 6000000 4.000000 10004000000 0 2001 2 0 4000000 5.000000 10005000000 0 2001 2 1000000 5000000 9.000000 10010400000 0 2002 3 400000 4400000 3.100000 10002146314 0 2000 1 2146314 6146314 3.140000 10002217270 0 2000 1 2217270 6217270 3.141593 10002220773 0 2000 1 2220773 6220773 0.500000 7770000000 0 1776 -1 0 4000000 0.250000 7764000000 0 1775 -2 0 4000000 0.125000 7760000000 0 1774 -3 0 4000000 -1.000000 27774000000 1 1777 0 0 4000000 -2.000000 30000000000 1 2000 1 0 4000000 -3.000000 30002000000 1 2000 1 2000000 6000000 -0.500000 27770000000 1 1776 -1 0 4000000 -3.141593 30002220773 1 2000 1 2220773 6220773