[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master f565b23 1/3: Resolve a clang complaint
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master f565b23 1/3: Resolve a clang complaint |
Date: |
Tue, 26 Sep 2017 20:29:21 -0400 (EDT) |
branch: master
commit f565b23d5db38a850c6075b59d2aa9a76e7a4c9f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Resolve a clang complaint
---
bourn_cast.hpp | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/bourn_cast.hpp b/bourn_cast.hpp
index 4453aa2..92d05b1 100644
--- a/bourn_cast.hpp
+++ b/bourn_cast.hpp
@@ -115,6 +115,25 @@ inline To bourn_cast(From from, std::false_type,
std::true_type)
return static_cast<To>(from);
}
+namespace lmi
+{
+/// A constexpr replacement for std::ldexp().
+///
+/// See:
+/// https://lists.nongnu.org/archive/html/lmi/2017-09/msg00003.html
+/// et seqq.
+
+template<typename T>
+constexpr T ldexp(T t, int exp)
+{
+ for(int i = 0; i < exp; ++i)
+ {
+ t *= T(2);
+ }
+ return t;
+}
+} // namespace lmi
+
/// Floating to integral.
///
/// Integral max() must be one less than an integer power of two,
@@ -174,7 +193,7 @@ inline To bourn_cast(From from, std::true_type,
std::false_type)
using from_traits = std::numeric_limits<From>;
static_assert(to_traits::is_integer && !from_traits::is_integer, "");
- constexpr From limit = std::ldexp(From(1), to_traits::digits);
+ constexpr From limit = lmi::ldexp(From(1), to_traits::digits);
constexpr bool is_twos_complement(~To(0) == -To(1));