lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master a110f9a0 04/11: Write fdlibm forwarding funct


From: Greg Chicares
Subject: [lmi-commits] [lmi] master a110f9a0 04/11: Write fdlibm forwarding functions out of line
Date: Thu, 26 May 2022 18:14:25 -0400 (EDT)

branch: master
commit a110f9a02d5c6db7ac42449af5d7779bdc15b7e5
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Write fdlibm forwarding functions out of line
    
    Writing these functions inline causes linker errors if the fdlibm
    objects are not specified, even for source files that include the
    header but don't use these functions.
    
    Provided simplistic overloads for types other than 'double', so
    that "std::" can be replaced by "lmi::" even for such types.
---
 Makefile.am             |  1 +
 math_functions.cpp      | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 math_functions.hpp      | 12 +++++++-----
 math_functions_test.cpp |  2 +-
 objects.make            |  1 +
 5 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f3701168..7d171807 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -878,6 +878,7 @@ materially_equal_test_LDADD = \
 math_functions_test_SOURCES = \
   fdlibm_expm1.c \
   fdlibm_log1p.c \
+  math_functions.cpp \
   math_functions_test.cpp
 math_functions_test_CXXFLAGS = $(AM_CXXFLAGS)
 math_functions_test_LDADD = \
diff --git a/math_functions.cpp b/math_functions.cpp
new file mode 100644
index 00000000..188df759
--- /dev/null
+++ b/math_functions.cpp
@@ -0,0 +1,46 @@
+// Miscellaneous mathematical operations.
+//
+// Copyright (C) 2022 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "pchfile.hpp"
+
+#include "math_functions.hpp"
+
+#include "fdlibm.hpp"                   // fdlibm_expm1(), fdlibm_log1p()
+
+// expm1() and log1p()
+//
+// Production uses only the 'double' overloads, which forward to
+// fdlibm implementations, which are substantially the same as
+// glibc's. Motivation: to use identical code for all x86_64
+// architectures, especially for MinGW-w64, whose implementations
+// are x87 code.
+//
+// For 'float' and 'long double', simply forward to the C RTL.
+
+namespace lmi
+{
+      float expm1(      float z) {return std::expm1(z);}
+      float log1p(      float z) {return std::log1p(z);}
+     double expm1(     double z) {return fdlibm_expm1(z);}
+     double log1p(     double z) {return fdlibm_log1p(z);}
+long double expm1(long double z) {return std::expm1(z);}
+long double log1p(long double z) {return std::log1p(z);}
+} // namespace lmi
diff --git a/math_functions.hpp b/math_functions.hpp
index 9add8696..f6f7a447 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -1,4 +1,4 @@
-// Miscellaneous mathematical operations as function objects.
+// Miscellaneous mathematical operations.
 //
 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 
2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Gregory W. Chicares.
 //
@@ -24,8 +24,6 @@
 
 #include "config.hpp"
 
-#include "fdlibm.hpp"                   // fdlibm_expm1(), fdlibm_log1p()
-
 #include <algorithm>                    // max(), min(), transform()
 #include <cmath>                        // expm1(), log1p(), signbit()
 #include <limits>
@@ -36,8 +34,12 @@
 
 namespace lmi
 {
-inline double expm1(double z) {return fdlibm_expm1(z);}
-inline double log1p(double z) {return fdlibm_log1p(z);}
+      float expm1(      float z);
+      float log1p(      float z);
+     double expm1(     double z);
+     double log1p(     double z);
+long double expm1(long double z);
+long double log1p(long double z);
 } // namespace lmi
 
 // TODO ?? Write functions here for other refactorable uses of
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 00854a3b..26434ad0 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -1,4 +1,4 @@
-// Miscellaneous mathematical operations as function objects--unit test.
+// Miscellaneous mathematical operations--unit test.
 //
 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Gregory W. Chicares.
 //
diff --git a/objects.make b/objects.make
index e102e0ac..3cadfa8a 100644
--- a/objects.make
+++ b/objects.make
@@ -793,6 +793,7 @@ math_functions_test$(EXEEXT): \
   $(common_test_objects) \
   fdlibm_expm1.o \
   fdlibm_log1p.o \
+  math_functions.o \
   math_functions_test.o \
   timer.o \
 



reply via email to

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