[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 46d02c5 03/10: Expunge inline replacements fo
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 46d02c5 03/10: Expunge inline replacements for std::fabs() and std::floor() [425] |
Date: |
Tue, 20 Dec 2016 01:31:04 +0000 (UTC) |
branch: master
commit 46d02c56f8d0bb5483c771a36b936d495cf8a898
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Expunge inline replacements for std::fabs() and std::floor() [425]
No compiler should get these wrong in this millennium.
---
round_to.hpp | 63 ++---------------------------------------------------
round_to_test.cpp | 6 ++---
2 files changed, 5 insertions(+), 64 deletions(-)
diff --git a/round_to.hpp b/round_to.hpp
index bce9beb..5a2217d 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -79,29 +79,6 @@ namespace detail
#ifdef LMI_BROKEN_FLOAT_AND_LONG_DOUBLE_CMATH_FNS
-// Returns the absolute value of 'r'. Somewhat defectively, assumes
-// that the negative of a negative argument is representable, which is
-// not guaranteed by C++98--but is OK for IEC 60559 floating-point
-// types, which can be negated by flipping the sign bit. However, it
-// might not be OK for non-IEC 60559 floating-point types. We might
-// assert std::numeric_limits<RealType>::is_iec559, but some compilers
-// (e.g. bc++5.5.1) would fail, perhaps properly, even though they run
-// on the same hardware as other compilers that would pass that test;
-// yet this is a property of the hardware, not of the compiler.
-
-template<typename RealType>
-RealType perform_fabs(RealType r)
-{
- if(r < RealType(0))
- {
- return -r;
- }
- else
- {
- return r;
- }
-}
-
// Returns 'r' raised to the 'n'th power. The sgi stl provides a faster
// implementation as an extension (although it does not seem to work
// with negative powers). Because this template function is called only
@@ -136,53 +113,17 @@ RealType perform_pow(RealType r, int n)
}
}
-// Returns largest integer-valued RealType value that does not exceed
-// its argument.
-template<typename RealType>
-RealType perform_floor(RealType r)
-{
- // Use std::floor() when we know it'll work; else just return
- // the argument. TODO ?? Isn't that incorrect for long double?
- static double const max_integral_double = perform_pow
- (2.0
- ,std::numeric_limits<double>::digits
- );
- if
- ( r < -max_integral_double
- || max_integral_double < r
- )
- {
- return r;
- }
- else
- {
- return std::floor(r);
- }
-}
-
#else // not defined LMI_BROKEN_FLOAT_AND_LONG_DOUBLE_CMATH_FNS
// Unlike the kludges above, these are defined inline to avoid
// penalizing compliant compilers.
template<typename RealType>
-inline RealType perform_fabs(RealType r)
-{
- return std::fabs(r);
-}
-
-template<typename RealType>
inline RealType perform_pow(RealType r, int n)
{
return std::pow(r, n);
}
-template<typename RealType>
-inline RealType perform_floor(RealType r)
-{
- return std::floor(r);
-}
-
#endif // not defined LMI_BROKEN_FLOAT_AND_LONG_DOUBLE_CMATH_FNS
} // namespace detail
@@ -334,7 +275,7 @@ RealType round_near(RealType r)
;
#endif // defined LMI_LACKING_RINT_OR_EQUIVALENT
RealType f_part = r - i_part;
- RealType abs_f_part = perform_fabs(f_part);
+ RealType abs_f_part = std::fabs(f_part);
// If |fractional part| < .5, ignore it;
// else if |fractional part| == .5, ignore it if integer part is even;
@@ -346,7 +287,7 @@ RealType round_near(RealType r)
RealType(0.5) == abs_f_part
&& i_part
!= RealType(2)
- * detail::perform_floor(RealType(0.5) * i_part)
+ * std::floor(RealType(0.5) * i_part)
)
)
{
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 206f94c..e013709 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -197,7 +197,7 @@ bool test_one_case
round_to<RealType> const f(decimals, style);
RealType observed = f(unrounded);
- max_prec_real abs_error = detail::perform_fabs(observed - expected);
+ max_prec_real abs_error = std::fabs(observed - expected);
// Nonstandardly define relative error in terms of
// o(bserved) and e(xpected) as
// |(o-e)/e| if e nonzero, else
@@ -207,7 +207,7 @@ bool test_one_case
max_prec_real rel_error(0.0);
if(max_prec_real(0.0) != expected)
{
- rel_error = detail::perform_fabs
+ rel_error = std::fabs
(
(observed - max_prec_real(expected))
/ expected
@@ -215,7 +215,7 @@ bool test_one_case
}
else if(max_prec_real(0.0) != observed)
{
- rel_error = detail::perform_fabs
+ rel_error = std::fabs
(
(observed - max_prec_real(expected))
/ observed
- [lmi-commits] [lmi] master updated (ae22927 -> 83d8eb3), Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 6cfeca5 02/10: Drop support for an ancient non-free compiler, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master dc47d4a 04/10: Improve documentation, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master fa18f82 01/10: Remove references to nonexistent html documentation, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master bdd39b7 08/10: Fix defect introduced 20050526T1235Z: precision loss, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 83d8eb3 10/10: Experimentally rely on optimization of pow(long double, int), Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master eff3c7f 09/10: Rename a member datum for concinnity, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 0f3563c 05/10: Simplify conditionals using certain object-like macros, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 46d02c5 03/10: Expunge inline replacements for std::fabs() and std::floor() [425],
Greg Chicares <=
- [lmi-commits] [lmi] master 54d2503 06/10: Presume std::rint() is available [424], Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 84ed793 07/10: Simplify preprocessor conditionals, Greg Chicares, 2016/12/19