Skip to content

Commit 24fa687

Browse files
authored
Merge pull request #334 from toughengineer/max-infinity_corner_cases
Added corner cases around max value/infinity
2 parents 83a4f69 + 88f6c5e commit 24fa687

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/basictest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,15 @@ TEST_CASE("double.inf") {
11421142
// DBL_MAX + 0.0000000000000001e308
11431143
verify("1.7976931348623159e308", std::numeric_limits<double>::infinity(),
11441144
std::errc::result_out_of_range);
1145+
1146+
// ( (2 - 0.5*2^(−52)) * 2^1023 ) smallest number that overflows to infinity
1147+
verify("179769313486231580793728971405303415079934132710037826936173778980444"
1148+
"968292764750946649017977587207096330286416692887910946555547851940402"
1149+
"630657488671505820681908902000708383676273854845817711531764475730270"
1150+
"069855571366959622842914819860834936475292719074168444365510704342711"
1151+
"559699508093042880177904174497792",
1152+
std::numeric_limits<double>::infinity(),
1153+
std::errc::result_out_of_range);
11451154
}
11461155

11471156
TEST_CASE("double.general") {
@@ -1333,6 +1342,15 @@ TEST_CASE("double.general") {
13331342
std::numeric_limits<double>::infinity(), std::errc::result_out_of_range);
13341343
verify("-2240084132271013504.131248280843119943687942846658579428",
13351344
-0x1.f1660a65b00bfp+60);
1345+
1346+
// ( (2 - 0.5*2^(−52)) * 2^1023 - 1 ) largest 309 decimal digit number
1347+
// that rounds to DBL_MAX
1348+
verify("179769313486231580793728971405303415079934132710037826936173778980444"
1349+
"968292764750946649017977587207096330286416692887910946555547851940402"
1350+
"630657488671505820681908902000708383676273854845817711531764475730270"
1351+
"069855571366959622842914819860834936475292719074168444365510704342711"
1352+
"559699508093042880177904174497791",
1353+
std::numeric_limits<double>::max());
13361354
}
13371355

13381356
TEST_CASE("double.decimal_point") {
@@ -1513,6 +1531,11 @@ TEST_CASE("float.inf") {
15131531
// FLT_MAX + 0.0000001e38
15141532
verify("3.4028236e38", std::numeric_limits<float>::infinity(),
15151533
std::errc::result_out_of_range);
1534+
1535+
// ( (2 - 0.5*2^(-23)) * 2^127 ) smallest number that overflows to infinity
1536+
verify("340282356779733661637539395458142568448",
1537+
std::numeric_limits<float>::infinity(),
1538+
std::errc::result_out_of_range);
15161539
}
15171540

15181541
TEST_CASE("float.general") {
@@ -1526,6 +1549,11 @@ TEST_CASE("float.general") {
15261549
// -max
15271550
verify("-340282346638528859811704183484516925440", -0x1.fffffep+127f);
15281551

1552+
// ( (2 - 0.5*2^(-23)) * 2^127 - 1 ) largest 39 decimal digits number
1553+
// that rounds to FLT_MAX
1554+
verify("340282356779733661637539395458142568447",
1555+
std::numeric_limits<float>::max());
1556+
15291557
verify("-1e-999", -0.0f, std::errc::result_out_of_range);
15301558
verify("1."
15311559
"175494140627517859246175898662808184331245864732796240031385942718174"

0 commit comments

Comments
 (0)