System.TSingleRec

提供: RAD Studio API Documentation
移動先: 案内検索

Delphi

  TSingleRec = packed record
  private
    aSingle: Single;
    function InternalGetBytes(Index: Cardinal): UInt8; inline;
    function InternalGetWords(Index: Cardinal): UInt16; inline;
    procedure InternalSetBytes(Index: Cardinal; const Value: UInt8); inline;
    procedure InternalSetWords(Index: Cardinal; const Value: UInt16); inline;
    function GetBytes(Index: Cardinal): UInt8; inline;
    function GetWords(Index: Cardinal): UInt16; inline;
    procedure SetBytes(Index: Cardinal; const Value: UInt8); inline;
    procedure SetWords(Index: Cardinal; const Value: UInt16); inline;
    function GetExp: UInt64; inline;
    function GetFrac: UInt64; inline;
    function GetSign: Boolean; inline;
    procedure SetExp(NewExp: UInt64);
    procedure SetFrac(NewFrac: UInt64);
    procedure SetSign(NewSign: Boolean);
  public
    function Exponent: Integer;
    function Fraction: Extended;
    function Mantissa: UInt64;
    property Sign: Boolean read GetSign write SetSign;
    property Exp: UInt64 read GetExp write SetExp;
    property Frac: UInt64 read GetFrac write SetFrac;
    function SpecialType: TFloatSpecial;
    procedure BuildUp(const SignFlag: Boolean; const Mantissa: UInt64; const Exponent: Integer);
    class operator Explicit(a: Extended): TSingleRec; inline;
    class operator Explicit(a: TSingleRec): Extended; inline;
    property Bytes[Index: Cardinal]: UInt8 read GetBytes write SetBytes;  // 0..3
    property Words[Index: Cardinal]: UInt16 read GetWords write SetWords; // 0..1
  end deprecated 'Use TSingleHelper';

C++

struct DECLSPEC_DRECORD TSingleRec
{
private:
    float aSingle;
    Byte __fastcall InternalGetBytes(unsigned Index);
    Word __fastcall InternalGetWords(unsigned Index);
    void __fastcall InternalSetBytes(unsigned Index, const Byte Value);
    void __fastcall InternalSetWords(unsigned Index, const Word Value);
    Byte __fastcall GetBytes(unsigned Index);
    Word __fastcall GetWords(unsigned Index);
    void __fastcall SetBytes(unsigned Index, const Byte Value);
    void __fastcall SetWords(unsigned Index, const Word Value);
    unsigned __int64 __fastcall GetExp(void);
    unsigned __int64 __fastcall GetFrac(void);
    bool __fastcall GetSign(void);
    void __fastcall SetExp(unsigned __int64 NewExp);
    void __fastcall SetFrac(unsigned __int64 NewFrac);
    void __fastcall SetSign(bool NewSign);
public:
    int __fastcall Exponent(void);
    Extended __fastcall Fraction(void);
    unsigned __int64 __fastcall Mantissa(void);
    __property bool Sign = {read=GetSign, write=SetSign};
    __property unsigned __int64 Exp = {read=GetExp, write=SetExp};
    __property unsigned __int64 Frac = {read=GetFrac, write=SetFrac};
    TFloatSpecial __fastcall SpecialType(void);
    void __fastcall BuildUp(const bool SignFlag, const unsigned __int64 Mantissa, const int Exponent);
    static TSingleRec __fastcall _op_Explicit(Extended a);
    __property Byte Bytes[unsigned Index] = {read=GetBytes, write=SetBytes};
    __property Word Words[unsigned Index] = {read=GetWords, write=SetWords};
};

プロパティ

種類 可視性 ソース ユニット
record
struct
public
System.pas
System.hpp
System System

説明

警告: TSingleRec は非推奨になっています。 SysUtils.TSingleHelper を使用してください。

TSingleRec では、単精度浮動小数点値に対して低レベル操作を実行できます。


XE3 では、Bytes プロパティと Words プロパティは配列プロパティになりました。High 関数と Low 関数は配列プロパティには適用されません。以下の例に示すように、System.SizeOf を代わりに使用できます。

この例の XE2 版では、以下のように、TSingleRec を 1 バイトずつ反復処理するのに System.HighSystem.Low が使用されていました。

  for I := High(F.Bytes) downto Low(F.Bytes) do

XE3 版の例では、以下のように、HighLow の代わりに System.SizeOf が使用されています。

 var
   F: TSingleRec;
   I: Integer;
 
 begin
   F := TSingleRec(-0.5);
 
   // display the hexadecimal representation of the single precision floating-point value
   // leftmost bytes are the most significant
   for I := sizeof(F) - 1 downto 0 do
     Write(IntToHex(F.Bytes[I], 2) + ' ');
   Writeln;
 
   // display the value contained in the TSingleRec record
   Writeln(FloatToStr(Single(F)));
 
   // ...

コンソール出力は以下のようになります。

BF 00 00 00
-0.5

関連項目