cgenmath.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2001 by Several contributors
  4. Generic mathemtical routines in libc
  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. { for 80x86, we can easily write the optimal inline code }
  12. {$ifndef cpui386}
  13. {$ifndef FPC_SYSTEM_HAS_INT}
  14. {$define FPC_SYSTEM_HAS_INT}
  15. {$ifdef SUPPORT_DOUBLE}
  16. function c_trunc(d: double): double; cdecl; external 'c' name 'trunc';
  17. {$ifdef INTERNCONSTINTF}
  18. function fpc_int_real(d: double): double;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  19. {$else}
  20. function int(d: double): double; {$ifdef MATHINLINE}inline;{$endif}[internconst:fpc_in_const_int];
  21. {$endif}
  22. begin
  23. result := c_trunc(d);
  24. end;
  25. {$else SUPPORT_DOUBLE}
  26. function c_truncf(d: real): double; cdecl; external 'c' name 'truncf';
  27. {$ifdef INTERNCONSTINTF}
  28. function fpc_int_real(d: real): real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  29. {$else}
  30. function int(d: real) : real;[internconst:fpc_in_const_int];
  31. {$endif}
  32. begin
  33. { this will be correct since real = single in the case of }
  34. { the motorola version of the compiler... }
  35. int:=c_truncf(d);
  36. end;
  37. {$endif SUPPORT_DOUBLE}
  38. {$endif}
  39. {$ifndef SYSTEM_HAS_FREXP}
  40. {$define SYSTEM_HAS_FREXP}
  41. function c_frexp(x: double; var e: longint): double; cdecl; external 'c' name 'frexp';
  42. function frexp(x:Real; var e:Integer ):Real; {$ifdef MATHINLINE}inline;{$endif}
  43. var
  44. l: longint;
  45. begin
  46. frexp := c_frexp(x,l);
  47. e := l;
  48. end;
  49. {$endif not SYSTEM_HAS_FREXP}
  50. {$ifndef SYSTEM_HAS_LDEXP}
  51. {$define SYSTEM_HAS_LDEXP}
  52. function c_ldexp(x: double; n: longint): double; cdecl; external 'c' name 'ldexp';
  53. function ldexp( x: Real; N: Integer):Real;{$ifdef MATHINLINE}inline;{$endif}
  54. begin
  55. ldexp := c_ldexp(x,n);
  56. end;
  57. {$endif not SYSTEM_HAS_LDEXP}
  58. {$ifndef FPC_SYSTEM_HAS_SQRT}
  59. {$define FPC_SYSTEM_HAS_SQRT}
  60. function c_sqrt(d: double): double; cdecl; external 'c' name 'sqrt';
  61. {$ifdef INTERNCONSTINTF}
  62. function fpc_sqrt_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  63. {$else}
  64. {$ifdef hascompilerproc}
  65. function fpc_sqrt_real(d:Real):Real;compilerproc; external name 'FPC_SQRT_REAL';
  66. {$endif hascompilerproc}
  67. function sqrt(d:Real):Real;[internconst:fpc_in_const_sqrt];[public, alias: 'FPC_SQRT_REAL']; {$ifdef MATHINLINE}inline;{$endif}
  68. {$endif}
  69. begin
  70. result := c_sqrt(d);
  71. end;
  72. {$endif}
  73. {$ifndef FPC_SYSTEM_HAS_EXP}
  74. {$define FPC_SYSTEM_HAS_EXP}
  75. function c_exp(d: double): double; cdecl; external 'c' name 'exp';
  76. {$ifdef INTERNCONSTINTF}
  77. function fpc_Exp_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  78. {$else}
  79. function Exp(d:Real):Real;[internconst:fpc_in_const_exp]; {$ifdef MATHINLINE}inline;{$endif}
  80. {$endif}
  81. begin
  82. result := c_exp(d);
  83. end;
  84. {$endif}
  85. (*
  86. Not supported on Mac OS X 10.1
  87. {$ifndef FPC_SYSTEM_HAS_ROUND}
  88. {$define FPC_SYSTEM_HAS_ROUND}
  89. function c_llround(d: double): int64; cdecl; external 'c' name 'llround';
  90. {$ifdef hascompilerproc}
  91. function round(d : Real) : int64;{$ifndef INTERNCONSTINTF}[internconst:fpc_in_const_round];{$endif} external name 'FPC_ROUND';
  92. function fpc_round(d : Real) : int64;[public, alias:'FPC_ROUND'];{$ifdef hascompilerproc}compilerproc;{$endif hascompilerproc}
  93. begin
  94. fpc_round := c_llround(d);
  95. end;
  96. {$else}
  97. function round(d : Real) : int64;{$ifndef INTERNCONSTINTF}[internconst:fpc_in_const_round];{$endif}
  98. begin
  99. round := c_llround(d);
  100. end;
  101. {$endif hascompilerproc}
  102. {$endif}
  103. *)
  104. {$ifndef FPC_SYSTEM_HAS_LN}
  105. {$define FPC_SYSTEM_HAS_LN}
  106. function c_log(d: double): double; cdecl; external 'c' name 'log';
  107. {$ifdef INTERNCONSTINTF}
  108. function fpc_Ln_real(d:Real):Real;compilerproc;{$ifdef MATHINLINE}inline;{$endif}
  109. {$else}
  110. function Ln(d:Real):Real;[internconst:fpc_in_const_ln];{$ifdef MATHINLINE}inline;{$endif}
  111. {$endif}
  112. begin
  113. result := c_log(d);
  114. end;
  115. {$endif}
  116. {$ifndef FPC_SYSTEM_HAS_SIN}
  117. {$define FPC_SYSTEM_HAS_SIN}
  118. function c_sin(d: double): double; cdecl; external 'c' name 'sin';
  119. {$ifdef INTERNCONSTINTF}
  120. function fpc_Sin_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  121. {$else}
  122. function Sin(d:Real):Real;[internconst:fpc_in_const_sin]; {$ifdef MATHINLINE}inline;{$endif}
  123. {$endif}
  124. begin
  125. result := c_sin(d);
  126. end;
  127. {$endif}
  128. {$ifndef FPC_SYSTEM_HAS_COS}
  129. {$define FPC_SYSTEM_HAS_COS}
  130. function c_cos(d: double): double; cdecl; external 'c' name 'cos';
  131. {$ifdef INTERNCONSTINTF}
  132. function fpc_Cos_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  133. {$else}
  134. function Cos(d:Real):Real;[internconst:fpc_in_const_cos];{$ifdef MATHINLINE}inline;{$endif}
  135. {$endif}
  136. begin
  137. result := c_cos(d);
  138. end;
  139. {$endif}
  140. {$ifndef FPC_SYSTEM_HAS_ARCTAN}
  141. {$define FPC_SYSTEM_HAS_ARCTAN}
  142. function c_atan(d: double): double; cdecl; external 'c' name 'atan';
  143. {$ifdef INTERNCONSTINTF}
  144. function fpc_ArcTan_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  145. {$else}
  146. function ArcTan(d:Real):Real;[internconst:fpc_in_const_arctan];{$ifdef MATHINLINE}inline;{$endif}
  147. {$endif}
  148. begin
  149. result := c_atan(d);
  150. end;
  151. {$endif}
  152. {$endif not i386}
  153. {
  154. $Log: cgenmath.inc,v $
  155. Revision 1.6 2005/02/14 17:13:22 peter
  156. * truncate log
  157. }