math.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team.
  4. Implementation of mathematical Routines (for extended type)
  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. {$asmmode intel}
  12. {****************************************************************************
  13. FPU Control word
  14. ****************************************************************************}
  15. procedure Set8087CW(cw:word);
  16. begin
  17. { pic-safe ; cw will not be a regvar because it's accessed from }
  18. { assembler }
  19. default8087cw:=cw;
  20. asm
  21. fnclex
  22. fldcw cw
  23. end;
  24. end;
  25. function Get8087CW:word;assembler;
  26. asm
  27. push bp
  28. mov bp, sp
  29. push ax
  30. fnstcw [bp - 2]
  31. pop ax
  32. mov sp, bp
  33. pop bp
  34. end;
  35. {****************************************************************************
  36. EXTENDED data type routines
  37. ****************************************************************************}
  38. {$define FPC_SYSTEM_HAS_PI}
  39. function fpc_pi_real : ValReal;compilerproc;
  40. begin
  41. { Function is handled internal in the compiler }
  42. runerror(207);
  43. result:=0;
  44. end;
  45. {$define FPC_SYSTEM_HAS_ABS}
  46. function fpc_abs_real(d : ValReal) : ValReal;compilerproc;
  47. begin
  48. { Function is handled internal in the compiler }
  49. runerror(207);
  50. result:=0;
  51. end;
  52. {$define FPC_SYSTEM_HAS_SQR}
  53. function fpc_sqr_real(d : ValReal) : ValReal;compilerproc;
  54. begin
  55. { Function is handled internal in the compiler }
  56. runerror(207);
  57. result:=0;
  58. end;
  59. {$define FPC_SYSTEM_HAS_SQRT}
  60. function fpc_sqrt_real(d : ValReal) : ValReal;compilerproc;
  61. begin
  62. { Function is handled internal in the compiler }
  63. runerror(207);
  64. result:=0;
  65. end;
  66. {$define FPC_SYSTEM_HAS_ARCTAN}
  67. function fpc_arctan_real(d : ValReal) : ValReal;compilerproc;
  68. begin
  69. { Function is handled internal in the compiler }
  70. runerror(207);
  71. result:=0;
  72. end;
  73. {$define FPC_SYSTEM_HAS_LN}
  74. function fpc_ln_real(d : ValReal) : ValReal;compilerproc;
  75. begin
  76. { Function is handled internal in the compiler }
  77. runerror(207);
  78. result:=0;
  79. end;
  80. {$define FPC_SYSTEM_HAS_SIN}
  81. function fpc_sin_real(d : ValReal) : ValReal;compilerproc;
  82. begin
  83. { Function is handled internal in the compiler }
  84. runerror(207);
  85. result:=0;
  86. end;
  87. {$define FPC_SYSTEM_HAS_COS}
  88. function fpc_cos_real(d : ValReal) : ValReal;compilerproc;
  89. begin
  90. { Function is handled internal in the compiler }
  91. runerror(207);
  92. result:=0;
  93. end;
  94. {$define FPC_SYSTEM_HAS_EXP}
  95. function fpc_exp_real(d : ValReal) : ValReal;assembler;compilerproc;
  96. var
  97. cw1,cw2: word;
  98. asm
  99. // comes from DJ GPP
  100. fld tbyte[d]
  101. fldl2e
  102. fmulp st(1), st
  103. fstcw CW1
  104. fstcw CW2
  105. fwait
  106. and CW2, $f3ff
  107. or CW2, $0400
  108. fldcw CW2
  109. fld st(0)
  110. frndint
  111. fldcw CW1
  112. fxch st(1)
  113. fsub st, st(1)
  114. f2xm1
  115. fld1
  116. faddp st(1), st
  117. fscale
  118. fstp st(1)
  119. end;
  120. {$define FPC_SYSTEM_HAS_INT}
  121. function fpc_int_real(d : ValReal) : ValReal;assembler;compilerproc;
  122. asm
  123. sub sp, 2
  124. fnstcw [bp-2]
  125. fwait
  126. mov cx, word [bp-2]
  127. or word [bp-2], $0f00
  128. fldcw [bp-2]
  129. fwait
  130. fld tbyte [d]
  131. frndint
  132. fwait
  133. mov word [bp-2], cx
  134. fldcw [bp-2]
  135. end;