[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 6fa7f99: Resolve more '-Wconversion' issues
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 6fa7f99: Resolve more '-Wconversion' issues |
Date: |
Thu, 31 May 2018 08:47:38 -0400 (EDT) |
branch: master
commit 6fa7f9942f60a53f94da3bebc5774a4918f45d14
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Resolve more '-Wconversion' issues
---
financial_test.cpp | 2 +-
group_quote_pdf_gen_wx.cpp | 12 +++++++++---
ieee754.hpp | 5 +++--
ieee754_test.cpp | 19 ++++++++++++++++---
ihs_basicval.cpp | 2 +-
ihs_crc_comp.cpp | 14 +++++++-------
ledger_pdf_generator_wx.cpp | 7 ++++---
ledger_text_formats.cpp | 3 ++-
materially_equal.hpp | 14 ++++----------
materially_equal_test.cpp | 4 ----
math_functions.hpp | 6 +++---
tn_range_test_aux.hpp | 2 +-
wx_utility.cpp | 5 +++--
13 files changed, 54 insertions(+), 41 deletions(-)
diff --git a/financial_test.cpp b/financial_test.cpp
index 18a6edd..1637a18 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -104,7 +104,7 @@ int test_main(int, char*[])
BOOST_TEST(std::fabs(r) <= 1e-13);
// Trivially, NPV at 0% interest is summation.
- BOOST_TEST(materially_equal(-4950.0, npv(q.begin(), q.end(), 0.0)));
+ BOOST_TEST(materially_equal(-4950.0L, npv(q.begin(), q.end(), 0.0)));
// Test const vectors.
std::vector<double> const cp(p);
diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 0773d0a..d8784c4 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -380,8 +380,8 @@ class group_quote_pdf_generator_wx
};
totals_data totals_;
- int row_num_ {0};
- int individual_selection_ {99};
+ int row_num_ {0};
+ bool individual_selection_ {}; // Initialized by add_ledger().
};
void assert_nonblank(std::string const& value, std::string const& name)
@@ -515,7 +515,13 @@ void group_quote_pdf_generator_wx::add_ledger(Ledger
const& ledger)
LedgerInvariant const& invar = ledger.GetLedgerInvariant();
- if(99 == individual_selection_) // no previous ledger processed yet
+ // 'GroupIndivSelection' isn't an input field, so it cannot be
+ // checked by assert_okay_to_run_group_quote(). It must be tested
+ // (here) because some legacy products unfortunately combined
+ // mandatory (unismoke) and voluntary (smoker-distinct) rates in
+ // the same plancode, when they should have used distinct subplans
+ // because they serve different market segments.
+ if(0 == row_num_)
{
individual_selection_ = invar.GroupIndivSelection;
}
diff --git a/ieee754.hpp b/ieee754.hpp
index 0a05134..f450793 100644
--- a/ieee754.hpp
+++ b/ieee754.hpp
@@ -37,10 +37,11 @@
/// specified if desired, although there's no guarantee that it won't
/// arise in practice. If none is specified, then we choose one with
/// FLT_DIG decimal digits and an exponent a bit under FLT_MAX_10_EXP,
-/// using the minimum values of those macros in C99 5.2.4.2.2/8.
+/// using the minimum values of those macros in C99 5.2.4.2.2/9, i.e.,
+/// six digits and absolute value < 1e37 = 10e36.
template<typename T>
-T implausible_value(T const& t = -9.99999e35)
+T implausible_value(T const& t = -9.99999e35f)
{
static_assert(::std::is_floating_point<T>::value);
diff --git a/ieee754_test.cpp b/ieee754_test.cpp
index 5aefe05..ee72e5a 100644
--- a/ieee754_test.cpp
+++ b/ieee754_test.cpp
@@ -33,16 +33,29 @@ int test_main(int, char*[])
BOOST_TEST(is_infinite(infinity<double >()));
BOOST_TEST(is_infinite(infinity<long double>()));
+ // Narrowing conversions commented out here:
BOOST_TEST(is_infinite<float >(-infinity<float >()));
- BOOST_TEST(is_infinite<float >(-infinity<double >()));
- BOOST_TEST(is_infinite<float >(-infinity<long double>()));
+// BOOST_TEST(is_infinite<float >(-infinity<double >()));
+// BOOST_TEST(is_infinite<float >(-infinity<long double>()));
BOOST_TEST(is_infinite<double >(-infinity<float >()));
BOOST_TEST(is_infinite<double >(-infinity<double >()));
- BOOST_TEST(is_infinite<double >(-infinity<long double>()));
+// BOOST_TEST(is_infinite<double >(-infinity<long double>()));
BOOST_TEST(is_infinite<long double>(-infinity<float >()));
BOOST_TEST(is_infinite<long double>(-infinity<double >()));
BOOST_TEST(is_infinite<long double>(-infinity<long double>()));
+ // Narrowing conversions tested here:
+#if defined __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wfloat-conversion"
+#endif // defined __GNUC__
+ BOOST_TEST(is_infinite<float >(-infinity<double >()));
+ BOOST_TEST(is_infinite<float >(-infinity<long double>()));
+ BOOST_TEST(is_infinite<double >(-infinity<long double>()));
+#if defined __GNUC__
+# pragma GCC diagnostic pop
+#endif // defined __GNUC__
+
BOOST_TEST(!is_infinite(0.0));
BOOST_TEST(!is_infinite( std::numeric_limits<double>::max()));
BOOST_TEST(!is_infinite(-std::numeric_limits<double>::max()));
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index f3494b0..8d20d3d 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -344,7 +344,7 @@ double BasicValues::InvestmentManagementFee() const
if(yare_input_.OverrideFundManagementFee)
{
- return yare_input_.InputFundManagementFee / 10000.0L;
+ return yare_input_.InputFundManagementFee / 10000.0;
}
double z = 0.0;
diff --git a/ihs_crc_comp.cpp b/ihs_crc_comp.cpp
index 1fd9a40..3104063 100644
--- a/ihs_crc_comp.cpp
+++ b/ihs_crc_comp.cpp
@@ -142,8 +142,8 @@ bool const transition_matrix[6][6] =
// "f" + "_" + to-state
std::string current_name;
-double max_abs_diff;
-double max_rel_err;
+long double max_abs_diff;
+long double max_rel_err;
//============================================================================
void show_error_context(std::string const& line1, std::string const& line2)
@@ -297,17 +297,17 @@ void f_3(std::string const& line1, std::string const&
line2)
return;
}
- double abs_diff = std::fabs(d1 - d2);
+ long double abs_diff = std::fabs(d1 - d2);
max_abs_diff = std::max(max_abs_diff, abs_diff);
- double rel_err =
+ long double rel_err =
std::fabs(
(d1 - d2)
/ ((0.0 == d1) ? d2 : d1)
);
max_rel_err = std::max(max_rel_err, rel_err);
- if(rel_err < 1.0E-11)
+ if(rel_err < 1.0E-11L)
{
return;
}
@@ -418,8 +418,8 @@ int try_main(int argc, char* argv[])
}
current_name = "";
- max_abs_diff = 0.0;
- max_rel_err = 0.0;
+ max_abs_diff = 0.0L;
+ max_rel_err = 0.0L;
// TODO ?? Want different things that match no type.
std::string line1 = "";
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 7d08aa0..dd1802b 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -2013,19 +2013,20 @@ class pdf_illustration_regular : public pdf_illustration
,state_abbrev == "IL" || state_abbrev == "TX"
);
+ int const inforce_year = bourn_cast<int>(invar.InforceYear);
add_variable
("UltimateInterestRate"
- ,evaluate("AnnGAIntRate_Current", invar.InforceYear + 1)
+ ,evaluate("AnnGAIntRate_Current", inforce_year + 1)
);
add_variable
("InforceYearEq0"
- ,invar.InforceYear == 0
+ ,inforce_year == 0
);
add_variable
("InforceYearLE4"
- ,invar.InforceYear < 4
+ ,inforce_year < 4
);
auto const max_duration = invar.EndtAge - invar.Age;
diff --git a/ledger_text_formats.cpp b/ledger_text_formats.cpp
index ab2fc5a..ea6a4a0 100644
--- a/ledger_text_formats.cpp
+++ b/ledger_text_formats.cpp
@@ -26,6 +26,7 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "authenticity.hpp"
+#include "bourn_cast.hpp"
#include "calendar_date.hpp"
#include "comma_punct.hpp"
#include "configurable_settings.hpp" //
effective_calculation_summary_columns()
@@ -1088,7 +1089,7 @@ void FlatTextLedgerPrinter::PrintNumericalSummary() const
// Illustration reg (7)(C)(2) "year in which coverage ceases".
auto const brink = [age, max_length] (LedgerVariant const& basis)
{
- int const z = basis.LapseYear;
+ int const z = bourn_cast<int>(basis.LapseYear);
std::string s =
(z < max_length)
? "Lapses in year " + value_cast<std::string>(1 + z)
diff --git a/materially_equal.hpp b/materially_equal.hpp
index 646e447..793f4f4 100644
--- a/materially_equal.hpp
+++ b/materially_equal.hpp
@@ -51,11 +51,8 @@
/// always treats nonzero quantities of opposite sign as materially
/// different.
-inline bool materially_equal
- (long double t
- ,long double u
- ,long double tolerance = 1.0E-13L
- )
+template<typename T>
+inline bool materially_equal(T t, T u, long double tolerance = 1.0E-13L)
{
return
t == u
@@ -76,11 +73,8 @@ inline bool materially_equal
/// that can assume an implausibly enormous value unless differences
/// that are mere rounding artifacts are not actively suppressed.
-inline long double material_difference
- (long double t
- ,long double u
- ,long double tolerance = 1.0E-13L
- )
+template<typename T>
+inline T material_difference(T t, T u, long double tolerance = 1.0E-13L)
{
return materially_equal(t, u, tolerance) ? 0.0 : t - u;
}
diff --git a/materially_equal_test.cpp b/materially_equal_test.cpp
index 230b026..1e332df 100644
--- a/materially_equal_test.cpp
+++ b/materially_equal_test.cpp
@@ -68,13 +68,9 @@ int test_main(int, char*[])
BOOST_TEST(!materially_equal(-1.0, -1.0 + 1.0E9 * epsilon));
BOOST_TEST(!materially_equal(1000000000.0, 1000000001.0));
- BOOST_TEST(!materially_equal(1000000000L , 1000000001.0));
- BOOST_TEST(!materially_equal(1000000000.0, 1000000001L ));
BOOST_TEST(!materially_equal(1000000000L , 1000000001L ));
BOOST_TEST( materially_equal(1000000000.0, 1000000001.0, 1.0E-9));
- BOOST_TEST( materially_equal(1000000000L , 1000000001.0, 1.0E-9));
- BOOST_TEST( materially_equal(1000000000.0, 1000000001L , 1.0E-9));
BOOST_TEST( materially_equal(1000000000L , 1000000001L , 1.0E-9));
long double bignum = std::numeric_limits<long double>::max();
diff --git a/math_functions.hpp b/math_functions.hpp
index 41f70a0..c48b95b 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -162,7 +162,7 @@ struct i_upper_12_over_12_from_i
static_assert(std::is_floating_point<T>::value);
T operator()(T const& i) const
{
- return i_upper_n_over_n_from_i<double,12>()(i);
+ return i_upper_n_over_n_from_i<T,12>()(i);
}
};
@@ -188,7 +188,7 @@ struct i_from_i_upper_12_over_12
static_assert(std::is_floating_point<T>::value);
T operator()(T const& i) const
{
- return i_from_i_upper_n_over_n<double,12>()(i);
+ return i_from_i_upper_n_over_n<T,12>()(i);
}
};
@@ -225,7 +225,7 @@ struct d_upper_12_from_i
static_assert(std::is_floating_point<T>::value);
T operator()(T const& i) const
{
- return d_upper_n_from_i<double,12>()(i);
+ return d_upper_n_from_i<T,12>()(i);
}
};
diff --git a/tn_range_test_aux.hpp b/tn_range_test_aux.hpp
index d0c49d0..2822bc3 100644
--- a/tn_range_test_aux.hpp
+++ b/tn_range_test_aux.hpp
@@ -57,7 +57,7 @@ typedef tn_range<int, percentage_trammel<int>>
r_int_percentage;
class RangeUDT
{
public:
- RangeUDT(): f_(3.14) {}
+ RangeUDT(): f_(3.14f) {}
RangeUDT(float f): f_(f) {}
bool operator==(RangeUDT const&) const {return true;}
diff --git a/wx_utility.cpp b/wx_utility.cpp
index 087478c..6bb9b60 100644
--- a/wx_utility.cpp
+++ b/wx_utility.cpp
@@ -25,6 +25,7 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
+#include "bourn_cast.hpp"
#include "calendar_date.hpp"
#include "contains.hpp"
#include "wx_new.hpp"
@@ -121,8 +122,8 @@ calendar_date ConvertDateFromWx(wxDateTime const& wx_date)
wxDateTime ConvertDateToWx(calendar_date const& lmi_date)
{
wxDateTime wx_date
- (lmi_date.day()
- ,static_cast<wxDateTime::Month>(lmi_date.month() - 1)
+ (bourn_cast <wxDateTime::wxDateTime_t>(lmi_date.day())
+ ,static_cast<wxDateTime::Month> (lmi_date.month() - 1)
,lmi_date.year()
);
AssertWxTimeIsMidnight(wx_date);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master 6fa7f99: Resolve more '-Wconversion' issues,
Greg Chicares <=