[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5011] Use infinity in product files
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5011] Use infinity in product files |
Date: |
Wed, 23 Jun 2010 00:53:33 +0000 |
Revision: 5011
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5011
Author: chicares
Date: 2010-06-23 00:53:32 +0000 (Wed, 23 Jun 2010)
Log Message:
-----------
Use infinity in product files
Modified Paths:
--------------
lmi/trunk/dbdict.cpp
lmi/trunk/print_matrix.hpp
lmi/trunk/stratified_algorithms.hpp
lmi/trunk/stratified_charges.cpp
lmi/trunk/stratified_charges.hpp
lmi/trunk/tier_view_editor.cpp
lmi/trunk/tier_view_editor.hpp
Modified: lmi/trunk/dbdict.cpp
===================================================================
--- lmi/trunk/dbdict.cpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/dbdict.cpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -35,6 +35,7 @@
#include "dbnames.hpp"
#include "global_settings.hpp"
#include "handle_exceptions.hpp"
+#include "ieee754.hpp" // infinity<>()
#include "mc_enum_type_enums.hpp"
#include "miscellany.hpp"
#include "oecumenic_enumerations.hpp"
@@ -46,8 +47,6 @@
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
-#include <limits>
-
template class xml_serializable<DBDictionary>;
std::string DBDictionary::cached_filename_;
@@ -489,7 +488,7 @@
void DBDictionary::InitDB()
{
- static double const bignum = std::numeric_limits<double>::max();
+ static double const dbl_inf = infinity<double>();
typedef std::vector<std::string>::const_iterator svci;
for(svci i = member_names().begin(); i != member_names().end(); ++i)
@@ -509,17 +508,17 @@
// e.g., 11 or 12.
Add(database_entity(DB_MaxMonthlyCoiRate , 12.0));
- Add(database_entity(DB_GuarIntSpread , bignum));
+ Add(database_entity(DB_GuarIntSpread , dbl_inf));
- Add(database_entity(DB_CurrCoiTable0Limit , bignum));
+ Add(database_entity(DB_CurrCoiTable0Limit , dbl_inf));
Add(database_entity(DB_CurrCoiTable1 , 999));
- Add(database_entity(DB_CurrCoiTable1Limit , bignum));
+ Add(database_entity(DB_CurrCoiTable1Limit , dbl_inf));
Add(database_entity(DB_CurrCoiTable2 , 999));
- Add(database_entity(DB_SpecAmtLoadLimit , bignum));
- Add(database_entity(DB_DynSepAcctLoadLimit , bignum));
- Add(database_entity(DB_AdbLimit , bignum));
- Add(database_entity(DB_ExpSpecAmtLimit , bignum));
+ Add(database_entity(DB_SpecAmtLoadLimit , dbl_inf));
+ Add(database_entity(DB_DynSepAcctLoadLimit , dbl_inf));
+ Add(database_entity(DB_AdbLimit , dbl_inf));
+ Add(database_entity(DB_ExpSpecAmtLimit , dbl_inf));
// SD Chapter 260 (HB 1200), signed 2008-02-19, amended 58-6-70
// by removing the former million-dollar threshold.
@@ -529,23 +528,22 @@
int premium_tax_dimensions[e_number_of_axes] = {1, 1, 1, 1, 1, 53, 1};
double premium_tax_retaliation_threshold[53] =
- {
- // AL AK AZ AR CA CO CT
- bignum, 0.0 , bignum, bignum, bignum, bignum, bignum,
- // DE DC FL GA HI ID
- bignum, bignum, bignum, bignum, bignum, bignum,
- // IL IN IA KS KY LA ME
- bignum, bignum, bignum, bignum, bignum, bignum, bignum,
- // MD MA MI MN MS MO
- bignum, bignum, bignum, bignum, bignum, bignum,
- // MT NE NV NH NJ NM NY
- bignum, bignum, bignum, bignum, bignum, bignum, bignum,
- // NC ND OH OK OR PA
- bignum, bignum, bignum, bignum, bignum, bignum,
- // PR RI SC SD TN TX UT
- bignum, bignum, bignum, 0.0 , bignum, bignum, bignum,
- // VT VA WA WV WI WY XX
- bignum, bignum, bignum, bignum, bignum, bignum, 0.0 ,
+ // AL AK AZ AR CA CO CT
+ {dbl_inf, 0.0, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // DE DC FL GA HI ID
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // IL IN IA KS KY LA ME
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // MD MA MI MN MS MO
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // MT NE NV NH NJ NM NY
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // NC ND OH OK OR PA
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf
+ // PR RI SC SD TN TX UT
+ ,dbl_inf, dbl_inf, dbl_inf, 0.0, dbl_inf, dbl_inf, dbl_inf
+ // VT VA WA WV WI WY XX
+ ,dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, dbl_inf, 0.0
};
Add
(database_entity
Modified: lmi/trunk/print_matrix.hpp
===================================================================
--- lmi/trunk/print_matrix.hpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/print_matrix.hpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -65,12 +65,9 @@
/// N modulo that vector. I have an expression of this in just a few
/// APL characters, which this character set is too small to contain.
///
-/// Future directions: Remove the suppression of axes of length one,
-/// which is specific to the product database. Make at least some
-/// effort to align data regularly. Consider adding labels for each
-/// hyperplane. Consider returning a string instead of writing
-/// directly to a std::ostream. Consider how to treat special values
-/// like DBL_MAX.
+/// Future directions: Consider adding labels for each hyperplane.
+/// Consider returning a string instead of writing directly to a
+/// std::ostream.
template<typename T>
void print_matrix
Modified: lmi/trunk/stratified_algorithms.hpp
===================================================================
--- lmi/trunk/stratified_algorithms.hpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/stratified_algorithms.hpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -51,8 +51,7 @@
///
/// Limits are constrained to be positive and nondecreasing. The first
/// bracket extends from zero (implicitly) to the first limit. The last
-/// limit must have no finite upper bound in the real number system; in
-/// computer floating point, it's specified as DBL_MAX.
+/// limit must be positive infinity.
///
/// It is convenient to characterize brackets by their upper limits.
/// Brackets may also be characterized in terms of incremental rather
@@ -128,9 +127,9 @@
/// Brackets are specified by incremental (not cumulative) limits.
///
/// TODO ?? This should be done implicitly:
-/// Use std::numeric_limits<T>::max() as the last element of
-/// 'incremental_limits' in order to apply the last element of 'rates'
-/// to any excess over the penultimate element of 'incremental_limits'.
+/// Use positive infinity as the last element of 'incremental_limits'
+/// in order to apply the last element of 'rates' to any excess over
+/// the penultimate element of 'incremental_limits'.
template<typename T>
struct tiered_product
@@ -306,11 +305,7 @@
std::vector<T> const& z(cumulative_limits);
LMI_ASSERT(nonstd::is_sorted(z.begin(), z.end()));
- // TODO ?? This is ghastly. As designed, the last limit must
- // exist, and it must equal std::numeric_limits<T>::max(); but
- // comparing that value to a stored copy for exact equality has
- // an indeterminate result. As a temporary workaround here, the
- // last value is ignored.
+ // Ignore the last limit. It's asserted elsewhere to be infinity.
std::vector<double>::const_iterator band = std::upper_bound
(cumulative_limits.begin()
,cumulative_limits.end() - 1
Modified: lmi/trunk/stratified_charges.cpp
===================================================================
--- lmi/trunk/stratified_charges.cpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/stratified_charges.cpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -33,7 +33,8 @@
#include "assert_lmi.hpp"
#include "contains.hpp"
#include "data_directory.hpp"
-#include "miscellany.hpp" // minmax<T>()
+#include "ieee754.hpp" // infinity<>()
+#include "miscellany.hpp" // minmax<>()
#include "stratified_algorithms.hpp"
#include "xml_lmi.hpp"
#include "xml_serialize.hpp"
@@ -41,7 +42,6 @@
#include <boost/static_assert.hpp>
#include <algorithm>
-#include <cfloat> // DBL_MAX
template class xml_serializable<stratified_charges>;
@@ -133,7 +133,7 @@
LMI_ASSERT(!values_.empty());
LMI_ASSERT(!limits_.empty());
LMI_ASSERT(values_.size() == limits_.size());
- LMI_ASSERT(is_highest_representable_double(limits_.back()));
+ LMI_ASSERT(infinity<double>() == limits_.back());
minmax<double> extrema(limits_);
LMI_ASSERT(0.0 <= extrema.minimum());
LMI_ASSERT(0.0 < extrema.maximum());
@@ -574,29 +574,31 @@
// http://lists.nongnu.org/archive/html/lmi/2008-02/msg00024.html
status() << "This line does nothing, but must not fail." << std::flush;
+ static double const dbl_inf = infinity<double>();
+
stratified_charges foo;
foo.datum("CurrSepAcctLoadBandedByPrem" ).values_.push_back(0.0);
- foo.datum("CurrSepAcctLoadBandedByPrem" ).limits_.push_back(DBL_MAX);
+ foo.datum("CurrSepAcctLoadBandedByPrem" ).limits_.push_back(dbl_inf);
foo.datum("GuarSepAcctLoadBandedByPrem" ).values_.push_back(0.0);
- foo.datum("GuarSepAcctLoadBandedByPrem" ).limits_.push_back(DBL_MAX);
+ foo.datum("GuarSepAcctLoadBandedByPrem" ).limits_.push_back(dbl_inf);
foo.datum("CurrSepAcctLoadBandedByAssets" ).values_.push_back(0.0);
- foo.datum("CurrSepAcctLoadBandedByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("CurrSepAcctLoadBandedByAssets" ).limits_.push_back(dbl_inf);
foo.datum("GuarSepAcctLoadBandedByAssets" ).values_.push_back(0.0);
- foo.datum("GuarSepAcctLoadBandedByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("GuarSepAcctLoadBandedByAssets" ).limits_.push_back(dbl_inf);
foo.datum("CurrMandETieredByAssets" ).values_.push_back(0.0);
- foo.datum("CurrMandETieredByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("CurrMandETieredByAssets" ).limits_.push_back(dbl_inf);
foo.datum("GuarMandETieredByAssets" ).values_.push_back(0.0);
- foo.datum("GuarMandETieredByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("GuarMandETieredByAssets" ).limits_.push_back(dbl_inf);
foo.datum("AssetCompTieredByAssets" ).values_.push_back(0.0);
- foo.datum("AssetCompTieredByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("AssetCompTieredByAssets" ).limits_.push_back(dbl_inf);
foo.datum("InvestmentMgmtFeeTieredByAssets").values_.push_back(0.0);
- foo.datum("InvestmentMgmtFeeTieredByAssets").limits_.push_back(DBL_MAX);
+ foo.datum("InvestmentMgmtFeeTieredByAssets").limits_.push_back(dbl_inf);
foo.datum("CurrSepAcctLoadTieredByAssets" ).values_.push_back(0.0);
- foo.datum("CurrSepAcctLoadTieredByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("CurrSepAcctLoadTieredByAssets" ).limits_.push_back(dbl_inf);
foo.datum("GuarSepAcctLoadTieredByAssets" ).values_.push_back(0.0);
- foo.datum("GuarSepAcctLoadTieredByAssets" ).limits_.push_back(DBL_MAX);
+ foo.datum("GuarSepAcctLoadTieredByAssets" ).limits_.push_back(dbl_inf);
// For AK and SD, these are the actual rates as of 2003-09-09. Statutes:
// AK 21.09.210(m)
@@ -605,36 +607,19 @@
foo.datum("TieredAKPremTax").values_.push_back (0.02700);
foo.datum("TieredAKPremTax").values_.push_back (0.00100);
foo.datum("TieredAKPremTax").limits_.push_back(100000.0);
- foo.datum("TieredAKPremTax").limits_.push_back(DBL_MAX);
+ foo.datum("TieredAKPremTax").limits_.push_back(dbl_inf);
foo.datum("TieredAKPremTax").gloss_ = "AK 21.09.210(m)";
// DE: not yet implemented.
foo.datum("TieredDEPremTax").values_.push_back (0.0);
- foo.datum("TieredDEPremTax").limits_.push_back(DBL_MAX);
+ foo.datum("TieredDEPremTax").limits_.push_back(dbl_inf);
foo.datum("TieredSDPremTax").values_.push_back (0.02500);
foo.datum("TieredSDPremTax").values_.push_back (0.00080);
foo.datum("TieredSDPremTax").limits_.push_back(100000.0);
- foo.datum("TieredSDPremTax").limits_.push_back(DBL_MAX);
+ foo.datum("TieredSDPremTax").limits_.push_back(dbl_inf);
foo.datum("TieredSDPremTax").gloss_ = "SD 10-4-22(2) (see also 58-6-70)";
foo.save(AddDataDir("sample.strata"));
}
-/// Determine whether a double is in effect the highest representable.
-///
-/// Don't assert exact equality with DBL_MAX, which is especially
-/// unlikely to obtain with values written to a file and then read
-/// back.
-///
-/// SOMEDAY !! Strive to obviate this function. It's used only to
-/// determine whether the top bracket's limit is effectively infinite.
-/// However, the top bracket's limit should never have any other
-/// value, so perhaps it should be treated as such implicitly, and not
-/// actually expressed.
-
-bool is_highest_representable_double(double z)
-{
- return (.999 * DBL_MAX) < z;
-}
-
Modified: lmi/trunk/stratified_charges.hpp
===================================================================
--- lmi/trunk/stratified_charges.hpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/stratified_charges.hpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -209,7 +209,5 @@
stratified_entity TieredSDPremTax;
};
-bool LMI_SO is_highest_representable_double(double);
-
#endif // stratified_charges_hpp
Modified: lmi/trunk/tier_view_editor.cpp
===================================================================
--- lmi/trunk/tier_view_editor.cpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/tier_view_editor.cpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -193,8 +193,6 @@
// TierEditorGrid implementation
// ---------------------------
-std::string TierEditorGrid::highest_representable_label_("MAXIMUM");
-
TierEditorGrid::TierEditorGrid()
{
}
@@ -314,19 +312,11 @@
std::string TierEditorGrid::DoubleToString(double value)
{
- if(is_highest_representable_double(value))
- {
- return highest_representable_label_;
- }
return value_cast<std::string>(value);
}
double TierEditorGrid::StringToDouble(std::string const& text)
{
- if(text == highest_representable_label_)
- {
- return DBL_MAX;
- }
return value_cast<double>(text);
}
Modified: lmi/trunk/tier_view_editor.hpp
===================================================================
--- lmi/trunk/tier_view_editor.hpp 2010-06-22 17:09:31 UTC (rev 5010)
+++ lmi/trunk/tier_view_editor.hpp 2010-06-23 00:53:32 UTC (rev 5011)
@@ -377,9 +377,6 @@
static std::string DoubleToString(double);
static double StringToDouble(std::string const&);
-
- // Label used in the editor for the highest representable number - DBL_MAX.
- static std::string highest_representable_label_;
};
#endif // tier_view_editor_hpp
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5011] Use infinity in product files,
Greg Chicares <=