mathh.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl,
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { i386 FPU Controlword }
  12. {$if defined(cpui8086) or defined(cpui386) or defined(cpux86_64)}
  13. const
  14. Default8087CW : word = $1332;
  15. procedure Set8087CW(cw:word);
  16. function Get8087CW:word;
  17. {$endif}
  18. {$if defined (cpui386) or defined(cpux86_64)}
  19. const
  20. DefaultMXCSR: dword = $1900;
  21. procedure SetMXCSR(w: dword);
  22. function GetMXCSR: dword;
  23. procedure SetSSECSR(w : dword); deprecated 'Renamed to SetMXCSR';
  24. function GetSSECSR : dword; deprecated 'Renamed to GetMXCSR';
  25. {$endif}
  26. type
  27. TFPURoundingMode = (rmNearest, rmDown, rmUp, rmTruncate);
  28. TFPUPrecisionMode = (pmSingle, pmReserved, pmDouble, pmExtended);
  29. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  30. exOverflow, exUnderflow, exPrecision);
  31. TFPUExceptionMask = set of TFPUException;
  32. const
  33. {*
  34. -------------------------------------------------------------------------------
  35. Software IEC/IEEE floating-point exception flags.
  36. -------------------------------------------------------------------------------
  37. *}
  38. float_flag_invalid = exInvalidOp;
  39. float_flag_denormal = exDenormalized;
  40. float_flag_divbyzero = exZeroDivide;
  41. float_flag_overflow = exOverflow;
  42. float_flag_underflow = exUnderflow;
  43. float_flag_inexact = exPrecision;
  44. {*
  45. -------------------------------------------------------------------------------
  46. Software IEC/IEEE floating-point rounding mode.
  47. -------------------------------------------------------------------------------
  48. *}
  49. float_round_nearest_even = rmNearest;
  50. float_round_down = rmDown;
  51. float_round_up = rmUp;
  52. float_round_to_zero = rmTruncate;
  53. {$ifdef FPC_HAS_FEATURE_THREADING}
  54. ThreadVar
  55. {$else FPC_HAS_FEATURE_THREADING}
  56. Var
  57. {$endif FPC_HAS_FEATURE_THREADING}
  58. softfloat_exception_mask : TFPUExceptionMask;
  59. softfloat_exception_flags : TFPUExceptionMask;
  60. softfloat_rounding_mode : TFPURoundingMode;
  61. procedure float_raise(i: TFPUException);
  62. procedure float_raise(i: TFPUExceptionMask);
  63. {$ifdef cpui386}
  64. {$define INTERNMATH}
  65. {$endif}
  66. {$ifndef INTERNMATH}
  67. {$ifdef FPC_USE_LIBC}
  68. {$ifdef SYSTEMINLINE}
  69. {$define MATHINLINE}
  70. {$endif}
  71. {$endif}
  72. {$endif}
  73. function pi : ValReal;[internproc:fpc_in_pi_real];
  74. function abs(d : ValReal) : ValReal;[internproc:fpc_in_abs_real];
  75. function sqr(d : ValReal) : ValReal;[internproc:fpc_in_sqr_real];
  76. function sqrt(d : ValReal) : ValReal;[internproc:fpc_in_sqrt_real];
  77. function arctan(d : ValReal) : ValReal;[internproc:fpc_in_arctan_real];
  78. function ln(d : ValReal) : ValReal;[internproc:fpc_in_ln_real];
  79. function sin(d : ValReal) : ValReal;[internproc:fpc_in_sin_real];
  80. function cos(d : ValReal) : ValReal;[internproc:fpc_in_cos_real];
  81. function exp(d : ValReal) : ValReal;[internproc:fpc_in_exp_real];
  82. function round(d : ValReal) : int64;[internproc:fpc_in_round_real];
  83. function frac(d : ValReal) : ValReal;[internproc:fpc_in_frac_real];
  84. function int(d : ValReal) : ValReal;[internproc:fpc_in_int_real];
  85. function trunc(d : ValReal) : int64;[internproc:fpc_in_trunc_real];
  86. {$ifdef SUPPORT_EXTENDED}
  87. function FPower10(val: Extended; Power: Longint): Extended;
  88. {$endif SUPPORT_EXTENDED}
  89. type
  90. real48 = array[0..5] of byte;
  91. {$ifdef SUPPORT_DOUBLE}
  92. function Real2Double(r : real48) : double;
  93. operator := (b:real48) d:double;
  94. {$endif}
  95. {$ifdef SUPPORT_EXTENDED}
  96. operator := (b:real48) e:extended;
  97. {$endif SUPPORT_EXTENDED}
  98. type
  99. TFloatSpecial = (fsZero,fsNZero,fsDenormal,fsNDenormal,fsPositive,fsNegative,
  100. fsInf,fsNInf,fsNaN,fsInvalidOp);
  101. {$ifdef SUPPORT_EXTENDED}
  102. TExtended80Rec = packed record
  103. private
  104. function GetExp : QWord;
  105. procedure SetExp(e : QWord);
  106. function GetSign : Boolean;
  107. procedure SetSign(s : Boolean);
  108. public
  109. function Mantissa : QWord;
  110. function Fraction : Extended;
  111. function Exponent : Longint;
  112. property Sign : Boolean read GetSign write SetSign;
  113. property Exp : QWord read GetExp write SetExp;
  114. function SpecialType : TFloatSpecial;
  115. // procedure BuildUp(const _Sign : Boolean; const _Mantissa : QWord; const Exponent : Longint);
  116. case byte of
  117. 0: (Bytes : array[0..9] of Byte);
  118. 1: (Words : array[0..4] of Word);
  119. {$ifdef ENDIAN_LITTLE}
  120. 2: (Frac : QWord; _Exp: Word);
  121. {$else ENDIAN_LITTLE}
  122. 2: (_Exp: Word; Frac : QWord);
  123. {$endif ENDIAN_LITTLE}
  124. 3: (Value: Extended);
  125. end;
  126. {$endif SUPPORT_EXTENDED}
  127. {$ifdef SUPPORT_DOUBLE}
  128. TDoubleRec = packed record
  129. private
  130. function GetExp : QWord;
  131. procedure SetExp(e : QWord);
  132. function GetSign : Boolean;
  133. procedure SetSign(s : Boolean);
  134. function GetFrac : QWord;
  135. procedure SetFrac(e : QWord);
  136. public
  137. function Mantissa : QWord;
  138. function Fraction : ValReal;
  139. function Exponent : Longint;
  140. property Sign : Boolean read GetSign write SetSign;
  141. property Exp : QWord read GetExp write SetExp;
  142. property Frac : QWord read Getfrac write SetFrac;
  143. function SpecialType : TFloatSpecial;
  144. case byte of
  145. 0: (Bytes : array[0..7] of Byte);
  146. 1: (Words : array[0..3] of Word);
  147. 2: (Data : QWord);
  148. 3: (Value: Double);
  149. end;
  150. {$endif SUPPORT_DOUBLE}
  151. {$ifdef SUPPORT_SINGLE}
  152. TSingleRec = packed record
  153. private
  154. function GetExp : QWord;
  155. procedure SetExp(e : QWord);
  156. function GetSign : Boolean;
  157. procedure SetSign(s : Boolean);
  158. function GetFrac : QWord;
  159. procedure SetFrac(e : QWord);
  160. public
  161. function Mantissa : QWord;
  162. function Fraction : ValReal;
  163. function Exponent : Longint;
  164. property Sign : Boolean read GetSign write SetSign;
  165. property Exp : QWord read GetExp write SetExp;
  166. property Frac : QWord read Getfrac write SetFrac;
  167. function SpecialType : TFloatSpecial;
  168. case byte of
  169. 0: (Bytes : array[0..3] of Byte);
  170. 1: (Words : array[0..1] of Word);
  171. 2: (Data : DWord);
  172. 3: (Value: Single);
  173. end;
  174. {$endif SUPPORT_SINGLE}
  175. function FMASingle(s1,s2,s3 : single) : single;[internproc:fpc_in_fma_single];
  176. {$ifdef SUPPORT_DOUBLE}
  177. function FMADouble(d1,d2,d3 : double) : double;[internproc:fpc_in_fma_double];
  178. {$endif SUPPORT_DOUBLE}
  179. {$ifdef SUPPORT_EXTENDED}
  180. function FMAExtended(e1,e2,e3 : extended) : extended;[internproc:fpc_in_fma_extended];
  181. {$endif SUPPORT_EXTENDED}
  182. {$ifdef SUPPORT_FLOAT128}
  183. function FMAFloat128(f1,f2,f3 : float128) : float128;[internproc:fpc_in_fma_float128];
  184. {$endif SUPPORT_FLOAT128}