From cd35cdad257ce9dfdca63a0aee287261156a18ca Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 13 Apr 2020 08:48:32 +0000 Subject: [PATCH] * fix Min/MaxSingle/Double values, resolves #36870 git-svn-id: trunk@44714 - --- .gitattributes | 1 + rtl/objpas/math.pp | 14 ++++++++++---- tests/test/units/math/tminmaxconst.pp | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 tests/test/units/math/tminmaxconst.pp diff --git a/.gitattributes b/.gitattributes index a3e844cb5f..f91cdc50ce 100644 --- a/.gitattributes +++ b/.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 diff --git a/rtl/objpas/math.pp b/rtl/objpas/math.pp index c391cf448f..38f73b207c 100644 --- a/rtl/objpas/math.pp +++ b/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 diff --git a/tests/test/units/math/tminmaxconst.pp b/tests/test/units/math/tminmaxconst.pp new file mode 100644 index 0000000000..b314319488 --- /dev/null +++ b/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.