Răsfoiți Sursa

* fix Min/MaxSingle/Double values, resolves #36870

git-svn-id: trunk@44714 -
florian 5 ani în urmă
părinte
comite
cd35cdad25
3 a modificat fișierele cu 35 adăugiri și 4 ștergeri
  1. 1 0
      .gitattributes
  2. 10 4
      rtl/objpas/math.pp
  3. 24 0
      tests/test/units/math/tminmaxconst.pp

+ 1 - 0
.gitattributes

@@ -15769,6 +15769,7 @@ tests/test/units/math/tdivmod.pp svneol=native#text/plain
 tests/test/units/math/tmask.inc svneol=native#text/plain
 tests/test/units/math/tmask.pp svneol=native#text/plain
 tests/test/units/math/tmask2.pp svneol=native#text/plain
+tests/test/units/math/tminmaxconst.pp svneol=native#text/pascal
 tests/test/units/math/tnaninf.pp svneol=native#text/plain
 tests/test/units/math/tpower.pp svneol=native#text/pascal
 tests/test/units/math/troundm.pp svneol=native#text/plain

+ 10 - 4
rtl/objpas/math.pp

@@ -71,13 +71,19 @@ Const
     { Ranges of the IEEE floating point types, including denormals }
 {$ifdef FPC_HAS_TYPE_SINGLE}
     const
-      MinSingle    =  1.5e-45;
-      MaxSingle    =  3.4e+38;
+      { values according to
+        https://en.wikipedia.org/wiki/Single-precision_floating-point_format#Single-precision_examples
+      }
+      MinSingle    =  1.1754943508e-38;
+      MaxSingle    =  3.4028234664e+38;
 {$endif FPC_HAS_TYPE_SINGLE}
 {$ifdef FPC_HAS_TYPE_DOUBLE}
     const
-      MinDouble    =  5.0e-324;
-      MaxDouble    =  1.7e+308;
+      { values according to
+        https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Double-precision_examples
+      }
+      MinDouble    =  2.2250738585072014e-308;
+      MaxDouble    =  1.7976931348623157e+308;
 {$endif FPC_HAS_TYPE_DOUBLE}
 {$ifdef FPC_HAS_TYPE_EXTENDED}
     const

+ 24 - 0
tests/test/units/math/tminmaxconst.pp

@@ -0,0 +1,24 @@
+uses
+  sysutils,math;
+var
+  s: Single;
+  d: Double;
+begin
+  s := MaxSingle;
+  d := MaxDouble;
+  Writeln(IntToHex(PLongInt(@s)^, 8));
+  if IntToHex(PLongInt(@s)^, 8)<>'7F7FFFFF' then
+     halt(1);
+  Writeln(IntToHex(PInt64(@d)^, 16));
+  if IntToHex(PInt64(@d)^, 16)<>'7FEFFFFFFFFFFFFF' then
+    halt(2);
+  s := MinSingle;
+  d := MinDouble;
+  Writeln(IntToHex(PLongInt(@s)^, 8));
+  if IntToHex(PLongInt(@s)^, 8)<>'00800000' then
+    halt(3);
+  Writeln(IntToHex(PInt64(@d)^, 16));
+  if IntToHex(PInt64(@d)^, 16)<>'0010000000000000' then
+    halt(4);
+  writeln('ok');
+end.