System.SysUtils.TSingleHelper

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

TSingleHelper = record helper for Single

C++

struct TSingleHelper /* Helper for real 'float' */;

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 single precision floating-point values.

Single numbers are represented on 32 bits: 1 bit for Sign, 8 for Exponent, and 23 for Fraction. The bias is 127. See Internal Representation of Single Type for more information.

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

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

Note: TSingleHelper offers the support that TSingleRec previously offered. TSingleRec is obsolete; use TSingleHelper instead.

Example

var
  aNumber: Single;
 
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: 131
Fraction: 600000
Mantissa: E00000

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

The number is positive, so Sign is 0 (False).

The Exponent is 4, represented in single precision as 127 (the bias) + 4 = 131. 131 is 10000011 ($83 in hexadecimal) 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 on 23 bits, so we fill the 1100 sequence up to 23 digits with zeros: 11000000000000000000000 ($600000 in hexadecimal).

The Mantissa is formed from the Fraction with a 1 bit before: 111000000000000000000000 ($E00000).

See Also

Code Examples