System.TExtended80Rec

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

Delphi

  TExtended80Rec = packed record
  private
{$IFDEF EXTENDEDIS10BYTES}
    aExtended80: Extended;
{$ELSE  !EXTENDEDIS10BYTES}
    aExtended80Frac: UInt64;
    aExtended80Exp:  UInt16;
{$ENDIF !EXTENDEDIS10BYTES}
    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;
    function GetWords(Index: Cardinal): UInt16;
    function Get_Exp: UInt64; inline;
    function GetExp: UInt64; inline;
    function GetFrac: UInt64; inline;
    function GetSign: Boolean; inline;
    procedure SetBytes(Index: Cardinal; const Value: UInt8);
    procedure SetWords(Index: Cardinal; const Value: UInt16);
    procedure Set_Exp(NewExp: UInt64); inline;
    procedure SetExp(NewExp: UInt64);
    procedure SetFrac(NewFrac: UInt64); inline;
    procedure SetSign(NewSign: Boolean);
  public
    function Exponent: Integer;
    function Fraction: Extended;
    function Mantissa: UInt64; inline;
    property Sign: Boolean read GetSign write SetSign;
    property Exp: UInt64 read GetExp write SetExp;
    property _Exp: UInt64 read Get_Exp write Set_Exp;
    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): TExtended80Rec;
    class operator Explicit(a: TExtended80Rec): Extended;
    property Bytes[Index: Cardinal]: UInt8 read GetBytes write SetBytes;  // 0..9
    property Words[Index: Cardinal]: UInt16 read GetWords write SetWords; // 0..4
  end;

C++

struct DECLSPEC_DRECORD TExtended80Rec
{
private:
#ifndef _WIN64
    Extended aExtended80;
#else /* _WIN64 */
    unsigned __int64 aExtended80Frac;
    Word aExtended80Exp;
#endif /* _WIN64 */
    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);
    unsigned __int64 __fastcall Get_Exp();
    unsigned __int64 __fastcall GetExp();
    unsigned __int64 __fastcall GetFrac();
    bool __fastcall GetSign();
    void __fastcall SetBytes(unsigned Index, const Byte Value);
    void __fastcall SetWords(unsigned Index, const Word Value);
    void __fastcall Set_Exp(unsigned __int64 NewExp);
    void __fastcall SetExp(unsigned __int64 NewExp);
    void __fastcall SetFrac(unsigned __int64 NewFrac);
    void __fastcall SetSign(bool NewSign);
public:
    int __fastcall Exponent();
    Extended __fastcall Fraction();
    unsigned __int64 __fastcall Mantissa();
    __property bool Sign = {read=GetSign, write=SetSign};
    __property unsigned __int64 Exp = {read=GetExp, write=SetExp};
    __property unsigned __int64 _Exp = {read=Get_Exp, write=Set_Exp};
    __property unsigned __int64 Frac = {read=GetFrac, write=SetFrac};
    TFloatSpecial __fastcall SpecialType();
    void __fastcall BuildUp(const bool SignFlag, const unsigned __int64 Mantissa, const int Exponent);
    static TExtended80Rec __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

説明

拡張精度浮動小数点値を操作するためのサポートを提供します。


TExtended80Rec は、拡張精度浮動小数点値に対して低レベル操作を実行するのに使用できます。たとえば、符号、指数、仮数を個別に変更できます。

Win32 版の Delphi では、データ型 Extended は 10 バイトです。ただし、Win64 版では、データ型 Extended は 8 バイトしかありません。Win64 環境で TExtended80Rec を使用すると、10 バイトの浮動小数点変数でメモリ関連操作を実行できます。ただし、拡張精度算術演算ではありません。

メモ:

  • 80 ビットの拡張精度浮動小数点型を操作する場合は、TExtendedHelper を使用することをお勧めします。ただし、TExtended80Rec が使用されなくなったわけではないので、TExtended80Rec を使用して 80 ビットの拡張精度実数データを割り当てることはできます。
  • XE3 では、Bytes プロパティと Words プロパティは配列プロパティになりました。High 関数と Low 関数は配列プロパティには適用されません。

 var
   F: TExtended80Rec;
   E: Extended;
   I: Integer;
 const
   TAB = Chr(9);
 begin
   F := TExtended80Rec(-66.3);
 
   Writeln('Sign: ' + TAB + TAB + IntToStr(Integer(F.Sign)));
   Writeln('Exponent: ' + TAB + IntToStr(Integer(F.Exp)));
   Writeln('Mantissa: ' + TAB + IntToHex(UInt64(F.Mantissa), 16));
 
   // Subtract 1 from exponent
   // This is equivalent with division by 2
   F.Exp := F.Exp - 1;
 
   E := Extended(F);
   Writeln('Size of Extended: ' + TAB + IntToStr(SizeOf(E))); // displays 10 on Win32 and 8 on Win64
   Writeln(FloatToStr(E)); // displays -33.15 (-66.3 / 2)
 
   // ...

Extended 型のサイズが 10 バイトの場合のコンソール出力:

Sign:          1
Exponent:       16389
Mantissa:       849999999999999A
Size of Extended:       10
-33.15

Extended 型のサイズが 8 バイトの場合のコンソール出力:

Sign:          1
Exponent:       16389
Mantissa:       8499999999999800
Size of Extended:       8
-33.15

Extended 型のサイズが 80 ビットであれば、浮動小数点定数 "-66.3" は 64 ビット精度で評価されます。しかし、Extended 型のサイズが 64 ビットであれば、たとえ TExtended80Rec で 64 ビットを処理できても、"-66.3" は 53 ビット精度でしか評価されません。Mantissa と Fraction に違いがあるのは、このためです。


関連項目