From Chessprogramming wiki
Jump to: navigation, search

Home * Programming * Data * Double

Double is a 64-bit data type representing the double precision floating-point format, in IEEE 754-1985 called double, in IEEE 754-2008 64-bit base 2 format is officially referred to as binary64. Due to normalization the true significand includes an implicit leading one bit unless the exponent is stored with all bits zeros or ones which are reserved for Denormal numbers. Thus only 52 bits of the significand are stored but the total precision is 53 bits (≈15.955 decimal digits). Exponent bias is 0x3FF (1023).


IEEE 754 Double Floating Point Format.svg

Double precision floating-point format

x86 Instruction Sets

Recent x86 and x86-64 processors provide x87, and SSE2 double precision floating point instruction sets. Since SSE2 is not obligatory for x86-32, 32-bit operating systems rely on x87. x86-64 64-bit operating systems may use the faster SSE2 instructions, but so far only 64-bit compiler for 64-bit Windows emit those instructions implicitly for double precision floating point operations [1] . SSE2 instructions can be mixed with x87 and are explicitly available through (inline) Assembly or intrinsics of various C-Compilers.

Integer to Double Conversion


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

FILD The FILD instruction converts a signed-integer in memory to double-extended-precision (10 bytes) 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 (4 bytes) or double-precision (8 bytes) 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.


[3][4] CVTDQ2PD Converts two packed 32-bit signed integer values in the low-order 64 bits of an XMM register or a 64-bit memory location to two packed double-precision floating-point values and writes the converted values in another XMM register.

CVTPI2PD Converts two packed 32-bit signed integer values in an MMX register or a 64-bit memory location to two double-precision floating-point values and writes the converted values in an XMM register.

CVTSI2SD Converts a 32-bit or 64-bit signed integer value in a general-purpose register or memory location to a double-precision floating-point value and writes the converted value in the low-order 64 bits of an XMM register. The high-order 64 bits in the destination XMM register are not modified.

  • Mnemonic: CVTSI2SD xmm, reg/mem32 (reg/mem64)
  • Intrinsic: _mm_cvtsi32_sd

BitScan Purpose

Integer to Double conversion can be used as base 2 logarithm of a power of two value of a 64-bit signed or unsigned integer, which might be used as 64-bit bitscan, as mentioned in Double conversion of LS1B and Double conversion.

See also


Forum Posts

External Links


Up one Level