lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [4958] Improve treatment of extreme or invalid arguments


From: Greg Chicares
Subject: [lmi-commits] [4958] Improve treatment of extreme or invalid arguments
Date: Sun, 23 May 2010 21:58:20 +0000

Revision: 4958
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4958
Author:   chicares
Date:     2010-05-23 21:58:20 +0000 (Sun, 23 May 2010)
Log Message:
-----------
Improve treatment of extreme or invalid arguments

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/math_functors.hpp
    lmi/trunk/math_functors_test.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-23 20:17:58 UTC (rev 4957)
+++ lmi/trunk/ChangeLog 2010-05-23 21:58:20 UTC (rev 4958)
@@ -25825,3 +25825,16 @@
   product_data.hpp
 Add new footnotes.
 
+20100523T2017Z <address@hidden> [704]
+
+  rounding_rules.cpp
+  rounding_rules.hpp
+Improve const-correctness.
+
+20100523T2158Z <address@hidden> [704]
+
+  math_functors.hpp
+  math_functors_test.cpp
+Improve treatment of extreme or invalid arguments. See:
+  http://lists.nongnu.org/archive/html/lmi/2010-05/msg00038.html
+

Modified: lmi/trunk/math_functors.hpp
===================================================================
--- lmi/trunk/math_functors.hpp 2010-05-23 20:17:58 UTC (rev 4957)
+++ lmi/trunk/math_functors.hpp 2010-05-23 21:58:20 UTC (rev 4958)
@@ -137,6 +137,16 @@
     BOOST_STATIC_ASSERT(0 < n);
     T operator()(T const& i) const
         {
+        if(i < -1.0)
+            {
+            throw std::domain_error("i is less than -100%.");
+            }
+
+        if(-1.0 == i)
+            {
+            return -1.0;
+            }
+
         static long double const reciprocal_n = 1.0L / n;
         // naively:    (1+i)^(1/n) - 1
         // substitute: (1+i)^n - 1 <-> expm1l(log1pl(i) * n)
@@ -190,6 +200,16 @@
     BOOST_STATIC_ASSERT(0 < n);
     T operator()(T const& i) const
         {
+        if(i < -1.0)
+            {
+            throw std::domain_error("i is less than -100%.");
+            }
+
+        if(-1.0 == i)
+            {
+            throw std::range_error("i equals -100%.");
+            }
+
         static long double const reciprocal_n = 1.0L / n;
         // naively:    n * (1 - (1+i)^(-1/n))
         // substitute: (1+i)^n - 1 <-> expm1l(log1pl(i) * n)
@@ -279,7 +299,7 @@
 
         if(q < 0.0)
             {
-            throw std::runtime_error("q is negative.");
+            throw std::domain_error("q is negative.");
             }
 
         if(0.0 == q)

Modified: lmi/trunk/math_functors_test.cpp
===================================================================
--- lmi/trunk/math_functors_test.cpp    2010-05-23 20:17:58 UTC (rev 4957)
+++ lmi/trunk/math_functors_test.cpp    2010-05-23 21:58:20 UTC (rev 4958)
@@ -256,11 +256,25 @@
 
     BOOST_TEST_EQUAL(-1.0 , i_upper_12_over_12_from_i_naive<double>()(-1.0));
     BOOST_TEST_EQUAL(-1.0 , i_upper_12_over_12_from_i      <double>()(-1.0));
+    BOOST_TEST_THROW
+        (d_upper_12_from_i        <double>()(-1.0)
+        ,std::range_error
+        ,"i equals -100%."
+        );
 
     // Test nonsensical interest rate of -101%.
 
     BOOST_TEST(lmi_isnan(i_upper_12_over_12_from_i_naive<double>()(-1.01)));
-    BOOST_TEST(lmi_isnan(i_upper_12_over_12_from_i<double>()      (-1.01)));
+    BOOST_TEST_THROW
+        (i_upper_12_over_12_from_i<double>()(-1.01)
+        ,std::domain_error
+        ,"i is less than -100%."
+        );
+    BOOST_TEST_THROW
+        (d_upper_12_from_i        <double>()(-1.01)
+        ,std::domain_error
+        ,"i is less than -100%."
+        );
 
     // Gross should equal net if decrements are both zero.
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]