mathu.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2003 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$ASMMODE ATT}
  13. {$define FPC_MATH_HAS_ARCTAN2}
  14. function arctan2(y,x : float) : float;assembler;
  15. asm
  16. fldt y
  17. fldt x
  18. fpatan
  19. fwait
  20. end;
  21. function GetRoundMode: TFPURoundingMode;
  22. begin
  23. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  24. end;
  25. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  26. var
  27. CtlWord: Word;
  28. begin
  29. CtlWord := Get8087CW;
  30. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  31. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  32. end;
  33. function GetPrecisionMode: TFPUPrecisionMode;
  34. begin
  35. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  36. end;
  37. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  38. var
  39. CtlWord: Word;
  40. begin
  41. CtlWord := Get8087CW;
  42. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  43. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  44. end;
  45. function GetExceptionMask: TFPUExceptionMask;
  46. begin
  47. Result := TFPUExceptionMask(Get8087CW and $3F);
  48. end;
  49. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  50. var
  51. CtlWord: Word;
  52. begin
  53. CtlWord := Get8087CW;
  54. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  55. Result := TFPUExceptionMask(CtlWord and $3F);
  56. end;
  57. procedure ClearExceptions(RaisePending: Boolean);assembler;
  58. asm
  59. cmpb $0,RaisePending
  60. je .Lclear
  61. fwait
  62. .Lclear:
  63. fnclex
  64. end;
  65. {
  66. $Log$
  67. Revision 1.3 2003-10-31 09:20:11 mazen
  68. + assembler mode forced to ATT style for x86 cpu
  69. Revision 1.2 2003/10/26 15:58:05 florian
  70. * fixed arctan2 to handle x=0 correctly as well
  71. Revision 1.1 2003/04/24 09:16:31 florian
  72. * initial implementation with code from math.pp
  73. }