mathu.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 by Florian Klaempfl
  4. member of the Free Pascal development team
  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. {$define FPC_MATH_HAS_ARCTAN2}
  12. function arctan2(y,x : float) : float;assembler;
  13. asm
  14. fldt y
  15. fldt x
  16. fpatan
  17. fwait
  18. end;
  19. procedure SetSSECSR(w : dword);
  20. var
  21. _w : dword;
  22. begin
  23. _w:=w;
  24. asm
  25. ldmxcsr _w
  26. end;
  27. end;
  28. function GetSSECSR : dword;
  29. var
  30. _w : dword;
  31. begin
  32. asm
  33. stmxcsr _w
  34. end;
  35. result:=_w;
  36. end;
  37. function GetRoundMode: TFPURoundingMode;
  38. begin
  39. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  40. end;
  41. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  42. var
  43. CtlWord: Word;
  44. begin
  45. CtlWord := Get8087CW;
  46. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  47. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  48. end;
  49. function GetPrecisionMode: TFPUPrecisionMode;
  50. begin
  51. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  52. end;
  53. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  54. var
  55. CtlWord: Word;
  56. begin
  57. CtlWord := Get8087CW;
  58. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  59. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  60. end;
  61. function GetExceptionMask: TFPUExceptionMask;
  62. begin
  63. Result := TFPUExceptionMask(dword(Get8087CW and $3F));
  64. end;
  65. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  66. var
  67. CtlWord: Word;
  68. begin
  69. CtlWord := Get8087CW;
  70. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  71. Result := TFPUExceptionMask(dword(CtlWord and $3F));
  72. end;
  73. procedure ClearExceptions(RaisePending: Boolean);assembler;
  74. asm
  75. cmpb $0,RaisePending
  76. je .Lclear
  77. fwait
  78. .Lclear:
  79. fnclex
  80. end;