[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master dd3abb11 18/22: Demonstrate a defect
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master dd3abb11 18/22: Demonstrate a defect |
Date: |
Fri, 20 May 2022 22:43:42 -0400 (EDT) |
branch: master
commit dd3abb11e03be4e9f6712c65f5b95df95f011c11
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Demonstrate a defect
---
Makefile.am | 2 ++
math_functions.hpp | 9 +++++++++
math_functions_test.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++
objects.make | 2 ++
4 files changed, 56 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 3f512af9..ea4982f2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -876,6 +876,8 @@ materially_equal_test_LDADD = \
libtest_common.la
math_functions_test_LDADD = \
+ fdlibm_expm1.c \
+ fdlibm_log1p.c \
libtest_common.la
mc_enum_test_SOURCES = \
diff --git a/math_functions.hpp b/math_functions.hpp
index 19c3e5e8..b32bd3c2 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -32,6 +32,15 @@
#include <type_traits> // /is_.*/
#include <vector>
+extern "C" double fdlibm_expm1(double);
+extern "C" double fdlibm_log1p(double);
+
+namespace lmi
+{
+inline double expm1(double z) {return fdlibm_expm1(z);}
+inline double log1p(double z) {return fdlibm_log1p(z);}
+} // namespace lmi
+
// TODO ?? Write functions here for other refactorable uses of
// std::pow() throughout lmi, to facilitate reuse and unit testing.
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index c2795f1e..2690607d 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -147,6 +147,47 @@ struct i_upper_n_over_n_from_i_T
};
} // Unnamed namespace.
+/// Test fdlibm expm1() and log1p().
+///
+/// Testing for exact floating-point equality seems to be a patent
+/// mistake, but should work for the fdlibm implementations on
+/// any implementation where double is binary64.
+
+void test_expm1_log1p()
+{
+ std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ std::cout.precision(23);
+
+ double const x = lmi::expm1(1.01);
+ double const y = lmi::log1p(0.01);
+ double const z = lmi::expm1(lmi::log1p(0.04) / 12);
+
+#if 0
+ // digits 1 23456789012345678901234
+ LMI_TEST_EQUAL(1.74560101501691655734305, x);
+ // digits 123456789012345678901
+ LMI_TEST_EQUAL(0.00995033085316808334209, y);
+ // digits 123456789012345678901
+ LMI_TEST_EQUAL(0.00327373978219886374239, z);
+#else // not 0
+ std::cout << "Those tests failed, so compare..." << std::endl;
+
+ double const a = std::expm1(1.01);
+ double const b = std::log1p(0.01);
+ double const c = std::expm1(std::log1p(0.04) / 12);
+
+ std::cout
+ << " " << x << " lmi::expm1(1.01)\n"
+ << " " << a << " std::expm1(1.01)\n"
+ << " " << y << " lmi::log1p(0.01)\n"
+ << " " << b << " std::log1p(0.01)\n"
+ << " " << z << " lmi::expm1(lmi::log1p(0.04) / 12)\n"
+ << " " << c << " std::expm1(std::log1p(0.04) / 12)\n"
+ << std::endl
+ ;
+#endif // not 0
+}
+
/// This function isn't a unit test per se. Its purpose is to show
/// how a sample calculation is affected by
/// exponential versus power method,
@@ -564,6 +605,8 @@ int test_main(int, char*[])
assay_speed();
+ test_expm1_log1p();
+
sample_results();
return 0;
diff --git a/objects.make b/objects.make
index 85d38976..e102e0ac 100644
--- a/objects.make
+++ b/objects.make
@@ -791,6 +791,8 @@ materially_equal_test$(EXEEXT): \
math_functions_test$(EXEEXT): \
$(common_test_objects) \
+ fdlibm_expm1.o \
+ fdlibm_log1p.o \
math_functions_test.o \
timer.o \
- [lmi-commits] [lmi] master updated (c4515973 -> 6c12b4ea), Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master c4e7bd93 01/22: Import expm1() and log1p() from fdlibm, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master e9f2f432 04/22: Canonicalize #include directives, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 5cc39664 03/22: Move a closing brace, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 1fd91fbf 10/22: Rename high- and low-word macros, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master fa7bbb53 05/22: Prefer lmi style, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 6b073770 08/22: Expunge unreferenced fdlibm versioning, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master cadb36d4 14/22: Don't include any fdlibm header, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 5b1ef5bb 15/22: Add prototypes, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master dd3abb11 18/22: Demonstrate a defect,
Greg Chicares <=
- [lmi-commits] [lmi] master af8d3ac0 21/22: Rationalize indentation of preprocessor directives, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 324e171e 02/22: Rectify whitespace, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 15b1aa35 11/22: Add license and copyright boilerplate, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 4ec9da1f 12/22: Rename fdlibm sources, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master e8a859a3 06/22: Rename prototyping macro, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 078e9a1c 16/22: Ignore certain diagnostics, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 2d514bdc 09/22: Allow some common macros, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 1646f4c0 13/22: Rename fdlibm entry points, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 75dc2686 17/22: Write unambiguous braces, Greg Chicares, 2022/05/20
- [lmi-commits] [lmi] master 9e608afe 20/22: Remove debugging output for tests that now succeed, Greg Chicares, 2022/05/20