mathu.inc 2.9 KB

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