2
0

mathu.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. begin
  20. set_fsr((get_fsr and $3fffffff) or (dword(RoundMode) shl 30));
  21. result:=TFPURoundingMode(get_fsr shr 30);
  22. end;
  23. function GetPrecisionMode: TFPUPrecisionMode;
  24. begin
  25. result:=pmDouble;
  26. end;
  27. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  28. begin
  29. result:=pmDouble;
  30. end;
  31. function GetExceptionMask: TFPUExceptionMask;
  32. var
  33. fsr : dword;
  34. begin
  35. fsr:=get_fsr;
  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,exInvalidOp);
  43. { overflow: bit 26 }
  44. if (fsr and (1 shl 26))=0 then
  45. include(result,exInvalidOp);
  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 SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  54. var
  55. fsr : dword;
  56. begin
  57. fsr:=get_fsr;
  58. { invalid operation: bit 27 }
  59. if (exInvalidOp in mask) then
  60. fsr:=fsr and not(1 shl 27)
  61. else
  62. fsr:=fsr or (1 shl 27);
  63. { zero divide: bit 24 }
  64. if (exZeroDivide in mask) then
  65. fsr:=fsr and not(1 shl 24)
  66. else
  67. fsr:=fsr or (1 shl 24);
  68. { overflow: bit 26 }
  69. if (exOverflow in mask) then
  70. fsr:=fsr and not(1 shl 26)
  71. else
  72. fsr:=fsr or (1 shl 26);
  73. { underflow: bit 25 }
  74. if (exUnderflow in mask) then
  75. fsr:=fsr and not(1 shl 25)
  76. else
  77. fsr:=fsr or (1 shl 25);
  78. { Precision (inexact result): bit 23 }
  79. if (exPrecision in mask) then
  80. fsr:=fsr and not(1 shl 23)
  81. else
  82. fsr:=fsr or (1 shl 23);
  83. { update control register contents }
  84. set_fsr(fsr);
  85. softfloat_exception_mask:=dword(Mask);
  86. end;
  87. procedure ClearExceptions(RaisePending: Boolean =true);
  88. begin
  89. set_fsr(get_fsr and $fffffc1f);
  90. end;