mathh.inc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. {$if defined(cpum68k)}
  27. {$if defined(fpu68881) or defined(fpucoldfire)}
  28. const
  29. {$ifdef FPC_68K_SYSTEM_HAS_FPU_EXCEPTIONS}
  30. Default68KFPCR: DWord = $3400; { Enable OVFL, OPERR and DZ, round to nearest, default precision }
  31. {$else}
  32. Default68KFPCR: DWord = 0;
  33. {$endif}
  34. procedure SetFPCR(x: DWord);
  35. procedure SetFPSR(x: DWord);
  36. function GetFPCR: DWord;
  37. function GetFPSR: DWord;
  38. {$endif}
  39. {$endif}
  40. type
  41. TFPURoundingMode = (rmNearest, rmDown, rmUp, rmTruncate);
  42. TFPUPrecisionMode = (pmSingle, pmReserved, pmDouble, pmExtended);
  43. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  44. exOverflow, exUnderflow, exPrecision);
  45. TFPUExceptionMask = set of TFPUException;
  46. const
  47. {*
  48. -------------------------------------------------------------------------------
  49. Software IEC/IEEE floating-point exception flags.
  50. -------------------------------------------------------------------------------
  51. *}
  52. float_flag_invalid = exInvalidOp;
  53. float_flag_denormal = exDenormalized;
  54. float_flag_divbyzero = exZeroDivide;
  55. float_flag_overflow = exOverflow;
  56. float_flag_underflow = exUnderflow;
  57. float_flag_inexact = exPrecision;
  58. {*
  59. -------------------------------------------------------------------------------
  60. Software IEC/IEEE floating-point rounding mode.
  61. -------------------------------------------------------------------------------
  62. *}
  63. float_round_nearest_even = rmNearest;
  64. float_round_down = rmDown;
  65. float_round_up = rmUp;
  66. float_round_to_zero = rmTruncate;
  67. {$ifdef FPC_HAS_FEATURE_THREADING}
  68. ThreadVar
  69. {$else FPC_HAS_FEATURE_THREADING}
  70. Var
  71. {$endif FPC_HAS_FEATURE_THREADING}
  72. softfloat_exception_mask : TFPUExceptionMask;
  73. softfloat_exception_flags : TFPUExceptionMask;
  74. softfloat_rounding_mode : TFPURoundingMode;
  75. procedure float_raise(i: TFPUException);
  76. procedure float_raise(i: TFPUExceptionMask);
  77. {$ifdef cpui386}
  78. {$define INTERNMATH}
  79. {$endif}
  80. {$ifndef INTERNMATH}
  81. {$ifdef FPC_USE_LIBC}
  82. {$ifdef SYSTEMINLINE}
  83. {$define MATHINLINE}
  84. {$endif}
  85. {$endif}
  86. {$endif}
  87. function pi : ValReal;[internproc:fpc_in_pi_real];
  88. function abs(d : ValReal) : ValReal;[internproc:fpc_in_abs_real];
  89. function sqr(d : ValReal) : ValReal;[internproc:fpc_in_sqr_real];
  90. function sqrt(d : ValReal) : ValReal;[internproc:fpc_in_sqrt_real];
  91. function arctan(d : ValReal) : ValReal;[internproc:fpc_in_arctan_real];
  92. function ln(d : ValReal) : ValReal;[internproc:fpc_in_ln_real];
  93. function sin(d : ValReal) : ValReal;[internproc:fpc_in_sin_real];
  94. function cos(d : ValReal) : ValReal;[internproc:fpc_in_cos_real];
  95. function exp(d : ValReal) : ValReal;[internproc:fpc_in_exp_real];
  96. function round(d : ValReal) : int64;[internproc:fpc_in_round_real];
  97. function frac(d : ValReal) : ValReal;[internproc:fpc_in_frac_real];
  98. function int(d : ValReal) : ValReal;[internproc:fpc_in_int_real];
  99. function trunc(d : ValReal) : int64;[internproc:fpc_in_trunc_real];
  100. {$ifdef SUPPORT_EXTENDED}
  101. function FPower10(val: Extended; Power: Longint): Extended;
  102. {$endif SUPPORT_EXTENDED}
  103. type
  104. real48 = array[0..5] of byte;
  105. {$ifdef SUPPORT_DOUBLE}
  106. function Real2Double(r : real48) : double;
  107. operator := (b:real48) d:double;
  108. {$endif}
  109. {$ifdef SUPPORT_EXTENDED}
  110. operator := (b:real48) e:extended;
  111. {$endif SUPPORT_EXTENDED}
  112. type
  113. TFloatSpecial = (fsZero,fsNZero,fsDenormal,fsNDenormal,fsPositive,fsNegative,
  114. fsInf,fsNInf,fsNaN,fsInvalidOp);
  115. {$if defined(SUPPORT_EXTENDED) or defined(FPC_SOFT_FPUX80)}
  116. TExtended80Rec = packed record
  117. private
  118. function GetExp : QWord;
  119. procedure SetExp(e : QWord);
  120. function GetSign : Boolean;
  121. procedure SetSign(s : Boolean);
  122. public
  123. function Mantissa : QWord;
  124. function Fraction : Extended;
  125. function Exponent : Longint;
  126. property Sign : Boolean read GetSign write SetSign;
  127. property Exp : QWord read GetExp write SetExp;
  128. function SpecialType : TFloatSpecial;
  129. // procedure BuildUp(const _Sign : Boolean; const _Mantissa : QWord; const Exponent : Longint);
  130. case byte of
  131. 0: (Bytes : array[0..9] of Byte);
  132. 1: (Words : array[0..4] of Word);
  133. {$ifdef ENDIAN_LITTLE}
  134. 2: (Frac : QWord; _Exp: Word);
  135. {$else ENDIAN_LITTLE}
  136. 2: (_Exp: Word; Frac : QWord);
  137. {$endif ENDIAN_LITTLE}
  138. {$ifdef SUPPORT_EXTENDED}
  139. 3: (Value: Extended);
  140. {$else}
  141. 3: (Value: array[0..9] of Byte);
  142. {$endif}
  143. end;
  144. {$endif SUPPORT_EXTENDED or FPC_SOFT_FPUX80}
  145. {$ifdef SUPPORT_DOUBLE}
  146. TDoubleRec = packed record
  147. private
  148. function GetExp : QWord;
  149. procedure SetExp(e : QWord);
  150. function GetSign : Boolean;
  151. procedure SetSign(s : Boolean);
  152. function GetFrac : QWord;
  153. procedure SetFrac(e : QWord);
  154. public
  155. function Mantissa : QWord;
  156. function Fraction : ValReal;
  157. function Exponent : Longint;
  158. property Sign : Boolean read GetSign write SetSign;
  159. property Exp : QWord read GetExp write SetExp;
  160. property Frac : QWord read Getfrac write SetFrac;
  161. function SpecialType : TFloatSpecial;
  162. case byte of
  163. 0: (Bytes : array[0..7] of Byte);
  164. 1: (Words : array[0..3] of Word);
  165. 2: (Data : QWord);
  166. 3: (Value: Double);
  167. end;
  168. {$endif SUPPORT_DOUBLE}
  169. {$ifdef SUPPORT_SINGLE}
  170. TSingleRec = packed record
  171. private
  172. function GetExp : QWord;
  173. procedure SetExp(e : QWord);
  174. function GetSign : Boolean;
  175. procedure SetSign(s : Boolean);
  176. function GetFrac : QWord;
  177. procedure SetFrac(e : QWord);
  178. public
  179. function Mantissa : QWord;
  180. function Fraction : ValReal;
  181. function Exponent : Longint;
  182. property Sign : Boolean read GetSign write SetSign;
  183. property Exp : QWord read GetExp write SetExp;
  184. property Frac : QWord read Getfrac write SetFrac;
  185. function SpecialType : TFloatSpecial;
  186. case byte of
  187. 0: (Bytes : array[0..3] of Byte);
  188. 1: (Words : array[0..1] of Word);
  189. 2: (Data : DWord);
  190. 3: (Value: Single);
  191. end;
  192. {$endif SUPPORT_SINGLE}
  193. function FMASingle(s1,s2,s3 : single) : single;[internproc:fpc_in_fma_single];
  194. {$ifdef SUPPORT_DOUBLE}
  195. function FMADouble(d1,d2,d3 : double) : double;[internproc:fpc_in_fma_double];
  196. {$endif SUPPORT_DOUBLE}
  197. {$ifdef SUPPORT_EXTENDED}
  198. function FMAExtended(e1,e2,e3 : extended) : extended;[internproc:fpc_in_fma_extended];
  199. {$endif SUPPORT_EXTENDED}
  200. {$ifdef SUPPORT_FLOAT128}
  201. function FMAFloat128(f1,f2,f3 : float128) : float128;[internproc:fpc_in_fma_float128];
  202. {$endif SUPPORT_FLOAT128}