mathu.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 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. { exported by the system unit }
  13. function get_fsr : dword;external name 'FPC_GETFSR';
  14. procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
  15. function GetRoundMode: TFPURoundingMode;
  16. begin
  17. result:=TFPURoundingMode(get_fsr shr 30);
  18. end;
  19. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  20. begin
  21. set_fsr((get_fsr and $3fffffff) or (dword(RoundMode) shl 30));
  22. result:=TFPURoundingMode(get_fsr shr 30);
  23. end;
  24. function GetPrecisionMode: TFPUPrecisionMode;
  25. begin
  26. result:=pmDouble;
  27. end;
  28. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  29. begin
  30. result:=pmDouble;
  31. end;
  32. function GetExceptionMask: TFPUExceptionMask;
  33. var
  34. fsr : dword;
  35. begin
  36. fsr:=get_fsr;
  37. result:=[];
  38. { invalid operation: bit 27 }
  39. if (fsr and (1 shl 27))=0 then
  40. include(result,exInvalidOp);
  41. { zero divide: bit 24 }
  42. if (fsr and (1 shl 24))=0 then
  43. include(result,exInvalidOp);
  44. { overflow: bit 26 }
  45. if (fsr and (1 shl 26))=0 then
  46. include(result,exInvalidOp);
  47. { underflow: bit 25 }
  48. if (fsr and (1 shl 25))=0 then
  49. include(result,exUnderflow);
  50. { Precision (inexact result): bit 23 }
  51. if (fsr and (1 shl 23))=0 then
  52. include(result,exPrecision);
  53. end;
  54. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  55. var
  56. fsr : dword;
  57. begin
  58. fsr:=get_fsr;
  59. { invalid operation: bit 27 }
  60. if (exInvalidOp in mask) then
  61. fsr:=fsr and not(1 shl 27)
  62. else
  63. fsr:=fsr or (1 shl 27);
  64. { zero divide: bit 24 }
  65. if (exZeroDivide in mask) then
  66. fsr:=fsr and not(1 shl 24)
  67. else
  68. fsr:=fsr or (1 shl 24);
  69. { overflow: bit 26 }
  70. if (exOverflow in mask) then
  71. fsr:=fsr and not(1 shl 26)
  72. else
  73. fsr:=fsr or (1 shl 26);
  74. { underflow: bit 25 }
  75. if (exUnderflow in mask) then
  76. fsr:=fsr and not(1 shl 25)
  77. else
  78. fsr:=fsr or (1 shl 25);
  79. { Precision (inexact result): bit 23 }
  80. if (exPrecision in mask) then
  81. fsr:=fsr and not(1 shl 23)
  82. else
  83. fsr:=fsr or (1 shl 23);
  84. { update control register contents }
  85. set_fsr(fsr);
  86. end;
  87. procedure ClearExceptions(RaisePending: Boolean {$ifndef VER1_0}=true{$endif});
  88. begin
  89. set_fsr(get_fsr and $fffffc1f);
  90. end;
  91. {
  92. $Log$
  93. Revision 1.3 2005-02-14 17:13:31 peter
  94. * truncate log
  95. Revision 1.2 2005/02/13 18:58:27 florian
  96. + FPU controll routines in math unit
  97. }