[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 6381b2f 44/65: Throw on overflow
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 6381b2f 44/65: Throw on overflow |
Date: |
Wed, 16 Sep 2020 16:55:19 -0400 (EDT) |
branch: valyuta/002
commit 6381b2f29d0871338261e69c166c47d6a9bf65e1
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Throw on overflow
---
currency.hpp | 2 +-
currency_test.cpp | 36 +++++++++++++++++++++++++-----------
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index be1992a..0a54a91 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -143,7 +143,7 @@ class currency
#else // 1
data_type round(double d) const
{
- return static_cast<data_type>(std::round(d));
+ return bourn_cast<data_type>(std::round(d));
}
#endif // 1
data_type m_ = {0};
diff --git a/currency_test.cpp b/currency_test.cpp
index 9ac6ae2..068c4e4 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -85,25 +85,39 @@ std::cout << "int3: " << big_int3 << std::endl;
currency::data_type big_int4 = round(100.0 * big_num);
std::cout << "int4: " << big_int4 << std::endl;
- currency a3(big_num / 1000.0);
-std::cout << a3 << std::endl;
-std::cout << big_num << std::endl;
-std::cout << "rounded: " << round(big_num) << std::endl;
+ BOOST_TEST_THROW
+ (currency a3(big_num / 1000.0)
+ ,std::runtime_error
+ ,"Cast would transgress upper limit."
+ );
+//std::cout << a3 << std::endl;
+//std::cout << big_num << std::endl;
+//std::cout << "rounded: " << round(big_num) << std::endl;
- std::cout << "\ntoo big:" << std::endl;
double too_big = std::numeric_limits<double>::max();
- currency a4(too_big);
-std::cout << a4 << std::endl;
-std::cout << too_big << std::endl;
-std::cout << "rounded: " << round(too_big) << std::endl;
-std::cout << 100.0 * too_big << std::endl;
+ BOOST_TEST_THROW
+ (currency a4(too_big)
+ ,std::runtime_error
+// ,"Cast would transgress upper limit."
+ ,"Cannot cast infinite to integral."
+ );
+// currency a4(too_big);
+//std::cout << a4 << std::endl;
+//std::cout << too_big << std::endl;
+//std::cout << "rounded: " << round(too_big) << std::endl;
+//std::cout << 100.0 * too_big << std::endl;
- std::cout << "\nstill too big:" << std::endl;
BOOST_TEST_THROW
(currency(bourn_cast<currency::data_type>(too_big))
,std::runtime_error
,"Cast would transgress upper limit."
);
+ BOOST_TEST_THROW
+ (currency xyzzy(too_big)
+ ,std::runtime_error
+// ,"Cast would transgress upper limit."
+ ,"Cannot cast infinite to integral."
+ );
currency b0(464.180000000000006821);
currency b1(263.01999999999998181);
- [lmi-commits] [lmi] valyuta/002 0cd4c10 27/65: There can be no operator*, (continued)
- [lmi-commits] [lmi] valyuta/002 0cd4c10 27/65: There can be no operator*, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c34960b 17/65: alternative for debugging, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 56ec06f 37/65: overload SetMonthlyDetail(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 518d684 28/65: Currency: implement binary operator+, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c07e796 08/65: use currency type, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 680dd5d 23/65: Revert "suppress failing assertions", Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 6b28993 06/65: clarify non-MEC solves, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 03262ae 16/65: commented-out curiosity, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 d63c5b3 33/65: round all the things, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 39eb954 36/65: symmetric binary operators, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 6381b2f 44/65: Throw on overflow,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 e0c5136 45/65: improve documentation, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7bac50c 50/65: default-initialize currency, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 f7f87b2 42/65: unit test: overflow, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9ea1df7 54/65: further improve preceding commit, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 ba43414 61/65: Record 64-bit timings, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 fb82290 63/65: Use maximal 64-bit rather than 32-bit integer value, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 bf1943b 03/65: reformat, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7481c2b 09/65: discard--throwaway assertions, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 998fdf5 35/65: operator/(), Greg Chicares, 2020/09/16