Float

Home * Programming * Data * Float

Float is a 32-bit data type representing the single precision floating-point format, in IEEE 754-1985 called single, in IEEE 754-2008 the 32-bit base 2 format is officially referred to as binary32. Due to normalization the true significand includes an implicit leading one bit unless the exponent is stored with all bits zeros (0x00) or ones (0xff) which are reserved for Denormal numbers. Thus only 23 bits of the significand are stored but the total precision is 24 bits (≈7.225 decimal digits). Exponent bias is 0x7f.

=Format= Single precision floating-point format

=x86 Float Instruction Sets= Recent x86 and x86-64 processors provide x87, SSE and 3DNow! (AMD only, shared with MMX/x87) floating point instruction sets. 3DNow! and SSE are SIMD instructions with vectors of two or four floats. Since SSE is not obligatory for x86-32, 32-bit operating systems rely on x87. x86-64 64-bit operating systems may use the faster SSE instructions, but so far only 64-bit compiler for 64-bit Windows emit those instructions implicitly for floating point operations. SSE instructions can be mixed with x87 or 3DNow! and are explicitly available through (inline) Assembly or intrinsics of various C-Compilers.

X87
To convert a signed or unsigned integer to float, two x87 instructions are needed, FILD and FSTP working on the x87 floating point stack.

FILD The FILD instruction converts a signed-integer in memory to double-extended-precision (80-bit) format and pushes the value onto the x87 register stack. The value can be a 16-bit, 32-bit, or 64- bit integer value. Signed values from memory can always be represented exactly in x87 registers without rounding.

FSTP The FSTP instruction pops the x87 stack after copying the value. The instruction FSTP ST(0) is the same as popping the stack with no data transfer. If the specified destination is a single-precision or double-precision memory location, the instruction converts the value to the appropriate precision format. It does this by rounding the significand of the source value as specified by the rounding mode determined by the RC field of the x87 control word and then converting to the format of destination. It also converts the exponent to the width and bias of the destination format.

SSE
CVTDQ2PS Converts four packed signed doubleword integers in the source operand (second operand) to four packed single-precision floating-point values in the destination operand (first operand).
 * Mnemonic: CVTDQ2PS xmm1, xmm2
 * Intrinsic: _mm_cvtepi32_ps

CVTPI2PS Converts two packed signed doubleword integers in the source operand (second operand) to two packed single-precision floating-point values in the destination operand (first operand).
 * Mnemonic: CVTPI2PS xmm, mm
 * Intrinsic: _mm_cvtpd_ps

3DNow!
PI2FD Converts packed 32-bit integer values to packed floating-point, single-precision values =BitScan Purpose= Integer to Float conversion can be used as base 2 logarithm of a power of two value of a 32-bit signed or unsigned integer, which might even base of a 64-bit bitscan. The 23 lower significant bits are always zero, the exponent contains the biased bitindex:
 * Mnemonic: PI2FD mm1, mm2
 * Intrinsic: _m_pi2fd

=See also=
 * Double Word
 * SSE
 * SSE2
 * Double

=Publications=
 * David Goldberg (1991). What every computer scientist should know about floating-point arithmetic. ACM Computing Surveys, pdf
 * Ward Douglas Maurer (1996). Relative Precision in the Inductive Assertion Method. WNAA 1996
 * Jacek Mańdziuk, Daniel Osman (2004). Alpha-Beta Search Enhancements with a Real-Value Game-State Evaluation Function. ICGA Journal, Vol. 27, No. 1, pdf
 * William W. Edmonson, Maarten H. van Emden (2008). Interval Semantics for Standard Floating-Point Arithmetic. arXiv:0810.4196

=Forum Posts=
 * Re: Which is better, IYHO by Ian Kennedy, rgcc, August 20, 1995
 * Re: Floating point VS Integer Math by Bruce Moreland, CCC, May 14, 1998
 * Evaluation functions. Why integer? by oysteijo, CCC, August 06, 2008 » Evaluation, Score
 * OT: denormals by Martin Sedlak, CCC, August 19, 2012
 * floating point SSE eval by Marco Belli, CCC, December 13, 2013 » Evaluation, Score

=External Links=
 * Floating point from Wikipedia
 * Single precision floating-point format from Wikipedia
 * Half-precision floating-point format from Wikipedia
 * Survey of Floating-Point Formats by Robert Munafo
 * About Floating Point Arithmetic from Johanns Blog

=References=

Up one Level