Skip to content

Commit

Permalink
C++11 support for numeric_limits<Half>::max_digits10() and lowest()
Browse files Browse the repository at this point in the history
  • Loading branch information
cary-ilm authored and nickrasmussen committed Aug 8, 2018
1 parent 47ea3f1 commit 781d47d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions IlmBase/Half/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions IlmBase/Half/halfLimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ class numeric_limits <half>
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

};


Expand Down
13 changes: 12 additions & 1 deletion IlmBase/HalfTest/testLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "halfLimits.h"
#include <iostream>
#include <assert.h>

#include <cmath>

using namespace std;

Expand Down Expand Up @@ -89,6 +89,17 @@ testLimits()
assert (h.isInfinity());
}

#if __cplusplus >= 201103L

cout << "max_digits10\n";
assert (numeric_limits<half>::max_digits10
== std::ceil(numeric_limits<half>::digits * std::log10(2) + 1));

cout << "lowest\n";
assert (numeric_limits<half>::lowest() == -HALF_MAX);

#endif

cout << "ok\n\n" << flush;

}

0 comments on commit 781d47d

Please sign in to comment.