math.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_EXP}
  81. function fpc_exp_real(d : ValReal) : ValReal;assembler;compilerproc;
  82. var
  83. cw1,cw2: word;
  84. asm
  85. // comes from DJ GPP
  86. fld tbyte[d]
  87. fldl2e
  88. fmulp st(1), st
  89. fstcw CW1
  90. fstcw CW2
  91. fwait
  92. and CW2, $f3ff
  93. or CW2, $0400
  94. fldcw CW2
  95. fld st(0)
  96. frndint
  97. fldcw CW1
  98. fxch st(1)
  99. fsub st, st(1)
  100. f2xm1
  101. fld1
  102. faddp st(1), st
  103. fscale
  104. fstp st(1)
  105. end;
  106. {$define FPC_SYSTEM_HAS_INT}
  107. function fpc_int_real(d : ValReal) : ValReal;assembler;compilerproc;
  108. asm
  109. sub sp, 2
  110. fnstcw [bp-2]
  111. fwait
  112. mov cx, word [bp-2]
  113. or word [bp-2], $0f00
  114. fldcw [bp-2]
  115. fwait
  116. fld tbyte [d]
  117. frndint
  118. fwait
  119. mov word [bp-2], cx
  120. fldcw [bp-2]
  121. end;
  122. {$define FPC_SYSTEM_HAS_TRUNC}
  123. function fpc_trunc_real(d : ValReal) : int64;assembler;compilerproc;
  124. asm
  125. sub sp, 10
  126. fld tbyte [d]
  127. fnstcw [bp-10]
  128. mov cx, [bp-10]
  129. or word [bp-10], $0f00
  130. fldcw [bp-10]
  131. mov [bp-10], cx
  132. fistp qword [bp-8]
  133. fldcw [bp-10]
  134. fwait
  135. mov dx, [bp-8]
  136. mov cx, [bp-6]
  137. mov bx, [bp-4]
  138. mov ax, [bp-2]
  139. end;