mathu.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. {$define FPC_MATH_HAS_ARCTAN2}
  13. function arctan2(y,x : float) : float;assembler;
  14. asm
  15. fldt y
  16. fldt x
  17. fpatan
  18. fwait
  19. end;
  20. function GetRoundMode: TFPURoundingMode;
  21. begin
  22. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  23. end;
  24. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  25. var
  26. CtlWord: Word;
  27. begin
  28. CtlWord := Get8087CW;
  29. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  30. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  31. end;
  32. function GetPrecisionMode: TFPUPrecisionMode;
  33. begin
  34. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  35. end;
  36. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  37. var
  38. CtlWord: Word;
  39. begin
  40. CtlWord := Get8087CW;
  41. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  42. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  43. end;
  44. function GetExceptionMask: TFPUExceptionMask;
  45. begin
  46. Result := TFPUExceptionMask(Get8087CW and $3F);
  47. end;
  48. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  49. var
  50. CtlWord: Word;
  51. begin
  52. CtlWord := Get8087CW;
  53. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  54. Result := TFPUExceptionMask(CtlWord and $3F);
  55. end;
  56. procedure ClearExceptions(RaisePending: Boolean);assembler;
  57. asm
  58. cmpb $0,RaisePending
  59. je .Lclear
  60. fwait
  61. .Lclear:
  62. fnclex
  63. end;
  64. {
  65. $Log$
  66. Revision 1.2 2003-10-26 15:58:05 florian
  67. * fixed arctan2 to handle x=0 correctly as well
  68. Revision 1.1 2003/04/24 09:16:31 florian
  69. * initial implementation with code from math.pp
  70. }