System.SysUtils.TExtendedHelper

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

TExtendedHelper = record helper for Extended

C++

struct TExtendedHelper /* Helper for real 'System::Extended' */;

Properties

Type Visibility Source Unit Parent
helper
class
public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Provides support for performing low-level operations on Extended precision floating-point values.

On 32-bit Windows, Extended numbers are represented in 80 bits: 1 bit for Sign, 15 for Exponent, and 64 for Fraction. The bias is 16383.

On 64-bit Windows and ARM platform, the Extended type is an alias for Double. Double numbers are represented in 64 bits: 1 bit for Sign, 11 for Exponent, and 52 for Fraction. The bias is 1023. See Internal Representation of Extended Type for more information.

For assigning all bits of a TExtendedHelper variable with the values given by Sign, Mantissa, and Exponent, use the BuildUp method.

The TExtendedHelper methods Exponent, Fraction, and Mantissa provide access to the raw parts of the number.

Note: On 32-bit Windows, TExtendedHelper offers the support that TExtended80Rec previously offered. If your program still manipulates 80-bit extended floating-point type on all platforms, the program can use the TExtended80Rec type.

Example

var
  aNumber: Extended;

begin  
  aNumber := 28;

  Writeln(Format('Number: %f', [aNumber])) ;
  Writeln(Format('Exponent: %d', [aNumber.Exp]));
  Writeln(Format('Fraction: %x', [aNumber.Frac]));
  Writeln(Format('Mantissa: %x', [aNumber.Mantissa]));
ReadLn;

Console output when SizeOf(Extended) is 10 bytes:

Number: 28.00
Exponent: 16387
Fraction: E000000000000000
Mantissa: E000000000000000

Console output when SizeOf(Extended) is 8 bytes:

Number: 28.00
Exponent: 1027
Fraction: C000000000000
Mantissa: 1C000000000000

The number 28 is represented in binary as 11100. After the normalization, it is 1.1100 * 2^4.

The Sign is 0 (False).

The exponent is 4. If the size of Extended is 10 bytes (for example, on the 32-bit Windows platform), Exponent is represented in extended precision as 16383 (the bias) + 4 = 16387. 16387 is 100000000000011 in binary.

If the size of Extended is 8 bytes (for example, on the 64-bit Windows platform), Exponent is represented as 1023 (the bias) + 4 = 1027. 1027 is 10000000011 in binary.

If the size of Extended is 10 bytes, the Fraction contains all bits of the Mantissa, also known as the significand, and is equal to 11100. The Fraction is represented in 64 bits, so we fill the 11100 sequence with zeros up to 64 digits:
11100000000000000000000000000000000000000000000000000 ($E000000000000000 in hexadecimal).

If the size of Extended is 8 bytes, the Fraction is formed from only the bits after the decimal mark in binary form and is equal to 1100, that is, the leading bit value of 1 is omitted. On such platforms, Fraction is represented in 52 bits, so we fill the 1100 sequence with zeros up to 52 digits:
11000000000000000000000000000000000000000000000000000 ($C000000000000).

The Mantissa, also known as the significand, contains all precision bits of the number 11100.

If the size of Extended is 10 bytes, the Mantissa is represented in 64 bits, so we fill the 11100 sequence with zeros up to 64 digits:
11100000000000000000000000000000000000000000000000000 ($E000000000000000).

If the size of Extended is 8 bytes , the Mantissa is represented in 53 bits, so we complete 11100 sequence with zeros up to 53 digits:
11100000000000000000000000000000000000000000000000000 ($1C000000000000).

See Also

Code Examples