diff --git a/IlmBase/Half/half.h b/IlmBase/Half/half.h index da418d65e1..ee8b24973f 100644 --- a/IlmBase/Half/half.h +++ b/IlmBase/Half/half.h @@ -277,6 +277,10 @@ HALF_EXPORT void printBits (char c[35], float f); #define HALF_DIG 2 // Number of base 10 digits that // can be represented without change +#define HALF_DECIMAL_DIG 5 // Number of base-10 digits that are + // necessary to uniquely represent all + // distinct values + #define HALF_RADIX 2 // Base of the exponent #define HALF_MIN_EXP -13 // Minimum negative integer such that diff --git a/IlmBase/Half/halfLimits.h b/IlmBase/Half/halfLimits.h index 404f58936b..351db8f7a0 100644 --- a/IlmBase/Half/halfLimits.h +++ b/IlmBase/Half/halfLimits.h @@ -94,6 +94,15 @@ class numeric_limits static const bool traps = true; static const bool tinyness_before = false; static const float_round_style round_style = round_to_nearest; + +#if __cplusplus >= 201103L + + // C++11 additions. + static constexpr int max_digits10 = HALF_DECIMAL_DIG; + static half lowest () {return -HALF_MAX;} + +#endif + }; diff --git a/IlmBase/HalfTest/testLimits.cpp b/IlmBase/HalfTest/testLimits.cpp index c26bedd9f5..d00835a6fd 100644 --- a/IlmBase/HalfTest/testLimits.cpp +++ b/IlmBase/HalfTest/testLimits.cpp @@ -2,7 +2,7 @@ #include "halfLimits.h" #include #include - +#include using namespace std; @@ -89,6 +89,17 @@ testLimits() assert (h.isInfinity()); } +#if __cplusplus >= 201103L + + cout << "max_digits10\n"; + assert (numeric_limits::max_digits10 + == std::ceil(numeric_limits::digits * std::log10(2) + 1)); + + cout << "lowest\n"; + assert (numeric_limits::lowest() == -HALF_MAX); + +#endif + cout << "ok\n\n" << flush; }