mathh.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl,
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { i386 FPU Controlword }
  13. {$ifdef cpui386}
  14. const
  15. Default8087CW : word = $1332;
  16. procedure Set8087CW(cw:word);
  17. function Get8087CW:word;
  18. {$endif cpui386}
  19. {$ifdef cpux86_64}
  20. const
  21. Default8087CW : word = $1332;
  22. procedure Set8087CW(cw:word);
  23. function Get8087CW:word;
  24. {$endif cpux86_64}
  25. { declarations of the math routines }
  26. {$ifdef cpui386}
  27. {$define INTERNMATH}
  28. {$endif}
  29. {$ifndef INTERNMATH}
  30. {$ifdef FPC_USE_LIBC}
  31. {$ifdef SYSTEMINLINE}
  32. {$define MATHINLINE}
  33. {$endif}
  34. {$endif}
  35. {$endif}
  36. {$ifdef internconstintf}
  37. {$ifdef INTERNMATH}
  38. {$define FPC_SYSTEM_HAS_PI}
  39. function pi : extended;[internproc:fpc_in_pi];
  40. {$define FPC_SYSTEM_HAS_ABS}
  41. function abs(d : extended) : extended;[internproc:fpc_in_abs_extended];
  42. {$define FPC_SYSTEM_HAS_SQR}
  43. function sqr(d : extended) : extended;[internproc:fpc_in_sqr_extended];
  44. {$define FPC_SYSTEM_HAS_SQRT}
  45. function sqrt(d : extended) : extended;[internproc:fpc_in_sqrt_extended];
  46. {$define FPC_SYSTEM_HAS_ARCTAN}
  47. function arctan(d : extended) : extended;[internproc:fpc_in_sqr_extended];
  48. {$define FPC_SYSTEM_HAS_LN}
  49. function ln(d : extended) : extended;[internproc:fpc_in_ln_extended];
  50. {$define FPC_SYSTEM_HAS_SIN}
  51. function sin(d : extended) : extended;[internproc:fpc_in_sin_extended];
  52. {$define FPC_SYSTEM_HAS_COS}
  53. function cos(d : extended) : extended;[internproc:fpc_in_cos_extended];
  54. function exp(d : extended) : extended;[internconst:fpc_in_const_exp];
  55. function round(d : extended) : int64;[internconst:fpc_in_const_exp];external name 'FPC_ROUND';
  56. function frac(d : extended) : extended;[internconst:fpc_in_const_frac];
  57. function int(d : extended) : extended;[internconst:fpc_in_const_int];
  58. function trunc(d : extended) : int64;[internconst:fpc_in_const_trunc];
  59. {$else}
  60. function abs(d : extended) : extended;[internconst:fpc_in_abs_extended];
  61. function arctan(d : extended) : extended;[internconst:fpc_in_arctan_extended];{$ifdef MATHINLINE}inline;{$endif}
  62. function cos(d : extended) : extended;[internconst:fpc_in_sqr_extended];{$ifdef MATHINLINE}inline;{$endif}
  63. function exp(d : extended) : extended;[internconst:fpc_in_const_exp];{$ifdef MATHINLINE}inline;{$endif}
  64. function frac(d : extended) : extended;[internconst:fpc_in_const_frac];
  65. function int(d : extended) : extended;[internconst:fpc_in_const_int];{$ifdef MATHINLINE}inline;{$endif}
  66. function ln(d : extended) : extended;[internconst:fpc_in_ln_extended];{$ifdef MATHINLINE}inline;{$endif}
  67. function pi : extended; [internconst:fpc_in_pi];
  68. function sin(d : extended) : extended;[internconst:fpc_in_sin_extended];{$ifdef MATHINLINE}inline;{$endif}
  69. function sqr(d : extended) : extended;[internconst:fpc_in_sqr_extended];
  70. function sqrt(d : extended) : extended;[internconst:fpc_in_sqrt_extended];{$ifdef MATHINLINE}inline;{$endif}
  71. function round(d : extended) : int64;[internconst:fpc_in_const_exp];
  72. function trunc(d : extended) : int64;[internconst:fpc_in_const_trunc];
  73. {$endif}
  74. {$else}
  75. function abs(d : extended) : extended;
  76. function arctan(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  77. function cos(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  78. function exp(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  79. function frac(d : extended) : extended;
  80. function int(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  81. function ln(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  82. function pi : extended;
  83. function sin(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  84. function sqr(d : extended) : extended;
  85. function sqrt(d : extended) : extended;{$ifdef MATHINLINE}inline;{$endif}
  86. function round(d : extended) : int64;
  87. function trunc(d : extended) : int64;
  88. {$endif internconstintf}
  89. function power(bas,expo : extended) : extended;
  90. function power(bas,expo : int64) : int64;
  91. {$ifdef FPC_CURRENCY_IS_INT64}
  92. function trunc(c : currency) : int64;
  93. function trunc(c : comp) : int64;
  94. function round(c : currency) : int64;
  95. function round(c : comp) : int64;
  96. {$endif FPC_CURRENCY_IS_INT64}
  97. type
  98. real48 = array[0..5] of byte;
  99. {$ifdef SUPPORT_DOUBLE}
  100. function Real2Double(r : real48) : double;
  101. operator := (b:real48) d:double;
  102. {$endif}
  103. {$ifdef SUPPORT_EXTENDED}
  104. operator := (b:real48) e:extended;
  105. {$endif SUPPORT_EXTENDED}
  106. {
  107. $Log$
  108. Revision 1.17 2004-11-17 22:19:04 peter
  109. internconst, internproc and some external declarations moved to interface
  110. Revision 1.16 2004/10/09 21:00:46 jonas
  111. + cgenmath with libc math functions. Faster than the routines in genmath
  112. and also have full double support (exp() only has support for values in
  113. the single range in genmath, for example). Used in FPC_USE_LIBC is
  114. defined
  115. * several fixes to allow compilation with -dHASINLINE, but internalerrors
  116. because of missing support for inlining assembler code
  117. Revision 1.15 2004/02/08 15:33:50 florian
  118. * linking problems fixed
  119. + abi tag added
  120. Revision 1.14 2004/01/02 17:19:04 jonas
  121. * if currency = int64, FPC_CURRENCY_IS_INT64 is defined
  122. + round and trunc for currency and comp if FPC_CURRENCY_IS_INT64 is
  123. defined
  124. * if currency = orddef, prefer currency -> int64/qword conversion over
  125. currency -> float conversions
  126. * optimized currency/currency if currency = orddef
  127. * TODO: write FPC_DIV_CURRENCY and FPC_MUL_CURRENCY routines to prevent
  128. precision loss if currency=int64 and bestreal = double
  129. Revision 1.13 2003/01/21 19:36:36 mazen
  130. - fpc_int64_to_double removed as not supported by most cpu targets
  131. Revision 1.12 2003/01/20 22:21:36 mazen
  132. * many stuff related to RTL fixed
  133. Revision 1.11 2003/01/15 00:40:18 peter
  134. * power returns int64
  135. Revision 1.10 2003/01/03 20:34:02 peter
  136. * i386 fpu controlword functions added
  137. Revision 1.9 2002/10/06 21:26:18 peter
  138. * round returns int64
  139. Revision 1.8 2002/09/07 15:07:45 peter
  140. * old logs removed and tabs fixed
  141. Revision 1.7 2002/07/26 22:46:06 florian
  142. * interface of system unit for Linux/PowerPC compiles
  143. }