cgenmath.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. function fpc_int_real(d: double): double;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  18. begin
  19. result := c_trunc(d);
  20. end;
  21. {$else SUPPORT_DOUBLE}
  22. function c_truncf(d: real): double; cdecl; external 'c' name 'truncf';
  23. function fpc_int_real(d: real): real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  24. begin
  25. { this will be correct since real = single in the case of }
  26. { the motorola version of the compiler... }
  27. int:=c_truncf(d);
  28. end;
  29. {$endif SUPPORT_DOUBLE}
  30. {$endif}
  31. {$ifndef SYSTEM_HAS_FREXP}
  32. {$define SYSTEM_HAS_FREXP}
  33. function c_frexp(x: double; out e: longint): double; cdecl; external 'c' name 'frexp';
  34. function frexp(x:Real; out e:Integer ):Real; {$ifdef MATHINLINE}inline;{$endif}
  35. var
  36. l: longint;
  37. begin
  38. frexp := c_frexp(x,l);
  39. e := l;
  40. end;
  41. {$endif not SYSTEM_HAS_FREXP}
  42. {$ifndef SYSTEM_HAS_LDEXP}
  43. {$define SYSTEM_HAS_LDEXP}
  44. function c_ldexp(x: double; n: longint): double; cdecl; external 'c' name 'ldexp';
  45. function ldexp( x: Real; N: Integer):Real;{$ifdef MATHINLINE}inline;{$endif}
  46. begin
  47. ldexp := c_ldexp(x,n);
  48. end;
  49. {$endif not SYSTEM_HAS_LDEXP}
  50. {$ifndef FPC_SYSTEM_HAS_SQRT}
  51. {$define FPC_SYSTEM_HAS_SQRT}
  52. function c_sqrt(d: double): double; cdecl; external 'c' name 'sqrt';
  53. function fpc_sqrt_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  54. begin
  55. result := c_sqrt(d);
  56. end;
  57. {$endif}
  58. {$ifndef FPC_SYSTEM_HAS_EXP}
  59. {$define FPC_SYSTEM_HAS_EXP}
  60. function c_exp(d: double): double; cdecl; external 'c' name 'exp';
  61. function fpc_Exp_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  62. begin
  63. result := c_exp(d);
  64. end;
  65. {$endif}
  66. (*
  67. Not supported on Mac OS X 10.1
  68. {$ifndef FPC_SYSTEM_HAS_ROUND}
  69. {$define FPC_SYSTEM_HAS_ROUND}
  70. function c_llround(d: double): int64; cdecl; external 'c' name 'llround';
  71. function round(d : Real) : int64; external name 'FPC_ROUND';
  72. function fpc_round(d : Real) : int64;[public, alias:'FPC_ROUND'];compilerproc;
  73. begin
  74. fpc_round := c_llround(d);
  75. end;
  76. {$endif}
  77. *)
  78. {$ifndef FPC_SYSTEM_HAS_LN}
  79. {$define FPC_SYSTEM_HAS_LN}
  80. function c_log(d: double): double; cdecl; external 'c' name 'log';
  81. function fpc_Ln_real(d:Real):Real;compilerproc;{$ifdef MATHINLINE}inline;{$endif}
  82. begin
  83. result := c_log(d);
  84. end;
  85. {$endif}
  86. {$ifndef FPC_SYSTEM_HAS_SIN}
  87. {$define FPC_SYSTEM_HAS_SIN}
  88. function c_sin(d: double): double; cdecl; external 'c' name 'sin';
  89. function fpc_Sin_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  90. begin
  91. result := c_sin(d);
  92. end;
  93. {$endif}
  94. {$ifndef FPC_SYSTEM_HAS_COS}
  95. {$define FPC_SYSTEM_HAS_COS}
  96. function c_cos(d: double): double; cdecl; external 'c' name 'cos';
  97. function fpc_Cos_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  98. begin
  99. result := c_cos(d);
  100. end;
  101. {$endif}
  102. {$ifndef FPC_SYSTEM_HAS_ARCTAN}
  103. {$define FPC_SYSTEM_HAS_ARCTAN}
  104. function c_atan(d: double): double; cdecl; external 'c' name 'atan';
  105. function fpc_ArcTan_real(d:Real):Real;compilerproc; {$ifdef MATHINLINE}inline;{$endif}
  106. begin
  107. result := c_atan(d);
  108. end;
  109. {$endif}
  110. {$endif not i386}