System.SysUtils.TDoubleHelper

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

TDoubleHelper = record helper for Double

C++

typedef void *TDoubleHelper;

Properties

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

Description

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

Double numbers are represented on 64 bits: 1 bit for Sign, 11 for Exponent, and 52 for Fraction. The bias is 1023. See Internal Representation of Double Type for more information.

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

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

Note: TDoubleHelper offers the support that TDoubleRec previously offered. TDoubleRec is obsolete; use TDoubleHelper instead.

Example

var
  aNumber: Double;
  
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]));
end;

Console output:

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.

The Exponent is 4, represented in single precision as 1023 (the bias) + 4 = 1027. 1027 is 10000000011 in binary.

The Fraction is formed from the bits after the decimal mark in binary form, namely, 1100, that is, the leading bit value of 1 is omitted. The Fraction is represented in 52 bits, so we fill the 1100 sequence up to 52 digits with zeros: 11000000000000000000000000000000000000000000000000000 ($C000000000000 in hexadecimal).

The Mantissa is formed from the Fraction with 1 bit before: 11100000000000000000000000000000000000000000000000000 ($1C000000000000).

See Also

Code Examples