[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 7bd1245 01/22: Add a unit test: root of anoth
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 7bd1245 01/22: Add a unit test: root of another unfriendly function |
Date: |
Sun, 6 Jun 2021 21:37:58 -0400 (EDT) |
branch: master
commit 7bd12452793484f6f9629e18e9bc820fe6af968e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add a unit test: root of another unfriendly function
---
zero_test.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/zero_test.cpp b/zero_test.cpp
index 5657440..a5b2f94 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -131,6 +131,18 @@ double eq_2_1(double x)
;
}
+/// A function for which bisection is optimal.
+///
+/// Return signum(argument + 1/3). Adding the constant makes it less
+/// likely that the root will be found by accident, e.g. between
+/// bounds such as (0,k) or (-k,k).
+
+double signum_offset(double d)
+{
+ double z = d + 1.0 / 3.0;
+ return (0.0 == z) ? 0.0 : std::signbit(z) ? -1.0 : 1.0;
+}
+
// This problem once arose in a unit test for irr calculations.
// Minimal test case:
//
@@ -243,6 +255,10 @@ int test_main(int, char*[])
LMI_TEST(root_is_valid == r.second);
LMI_TEST(-100.0 <= r.first && r.first <= -100.0 * (1.0 - 6.0 * epsilon));
+ r = decimal_root(-1.0, 1.0, bias_none, 13, signum_offset);
+ LMI_TEST(root_is_valid == r.second);
+ LMI_TEST(materially_equal(-1.0 / 3.0, r.first));
+
e_former_rounding_problem e_frp;
r = decimal_root(0.12609, 0.12611, bias_lower, 5, e_frp);
#if !defined LMI_COMO_WITH_MINGW
- [lmi-commits] [lmi] master updated (f0526be -> 86661b6), Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 7bd1245 01/22: Add a unit test: root of another unfriendly function,
Greg Chicares <=
- [lmi-commits] [lmi] master c01b9b0 02/22: Improve concinnity, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 012967c 08/22: Diagnose any attempt to find a root in a zero-measure interval, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 83eb025 05/22: Rename a local variable, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master ec0a308 06/22: Refactor, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return value more flexibly, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 5c31ab3 09/22: Fix latent unit-test errors, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 2391573 11/22: Rename a variable, for terseness, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master b14e318 18/22: Adjust tolerance for a particular unit-test function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1c448d8 20/22: Augment decimal_root()'s return type, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 53c3513 21/22: Reorder unit tests, Greg Chicares, 2021/06/06