IEEE 754 formats

From Free Pascal wiki
Jump to navigationJump to search

English (en)

single, double and extended are FPC's data types implementing Pascal’s real. All of them are implemented according IEEE standard 754, where single is “single-precision”, double is “double-precision”, and extended has 80 bits.


value range 1.5E-45 .. 3.4E38
accuracy 6-9 significant decimal digits precision
memory requirement 4 bytes or 32 bits
property The single- data-type data field can hold floating-point values ​​and signed and unsigned integer values.

Assigning other values ​​will result in error messages from the compiler when the program is compiled, and the compile will be aborted. That is, the executable program is not created.

Definition of a data field of data type Single:

  s: single;

Examples of assigning valid values:

s := -123.45678;
// Note: '0' is an integer literal. 0.0 is an real literal.
// Here, FPC will make an implicit typecast from integer to single:
s := 0;
// a positive sign is optional
s := 123.45678;

Examples of assigning invalid values:

s := '-123.45678';
s := '0';
s := '123.45678';

The difference between the two examples is that the upper example is the assignment of Integer and FloatingCommand literals, while the assignment of the lower example is literals of the String type.

Binary floating-point format

Any value stored as a single requires 32 bits, formatted as shown in the table below:

Bits Usage
31 Sign (0 = positive, 1 = negative)
30 to 23 Exponent, biased by 127
22 to 0 Fraction f of the number 1.f


Any value stored as a double requires 64 bits, formatted as shown in the table below:

Bits Usage
63 Sign (0 = positive, 1 = negative)
62 to 52 Exponent, biased by 1023
51 to 0 Fraction f of the number 1.f

Example of converting from raw data to double (Data is array [0..7] of byte):

function ToDouble(const Data; IntelEndianness: Boolean = False):Double;inline;
  ADouble: Double absolute Data;
  AQWord: QWord absolute Result;
  Result := ADouble;
  if not IntelEndianness then
    AQWord := SwapEndian(AQWord);


extended is a 80-bit wide floating-point data type. There are FPUs that internally use 80 bits for increased precision. FPC allows to use this gain in precision.


Note: If some platform does not support the extended data type, it will be mapped to largest available floating-point number data available, i. e. usually double.

navigation bar: data types
simple data types

boolean byte cardinal char currency double dword extended int8 int16 int32 int64 integer longint real shortint single smallint pointer qword word

complex data types

array class object record set string shortstring