Use C++ limits where applicable for portability
This commit is contained in:
parent
befae3c0b0
commit
af9c5e05f7
2 changed files with 14 additions and 12 deletions
|
@ -56,6 +56,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -76,6 +77,8 @@ extern Tick curTick;
|
||||||
/* A namespace for all of the Statistics */
|
/* A namespace for all of the Statistics */
|
||||||
namespace Stats {
|
namespace Stats {
|
||||||
|
|
||||||
|
typedef std::numeric_limits<Counter> CounterLimits;
|
||||||
|
|
||||||
/* Contains the statistic implementation details */
|
/* Contains the statistic implementation details */
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -1454,8 +1457,8 @@ struct DistStor
|
||||||
data->bucket_size = params.bucket_size;
|
data->bucket_size = params.bucket_size;
|
||||||
data->size = params.size;
|
data->size = params.size;
|
||||||
|
|
||||||
data->min_val = (min_val == INT_MAX) ? 0 : min_val;
|
data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
|
||||||
data->max_val = (max_val == INT_MIN) ? 0 : max_val;
|
data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
|
||||||
data->underflow = underflow;
|
data->underflow = underflow;
|
||||||
data->overflow = overflow;
|
data->overflow = overflow;
|
||||||
data->cvec.resize(params.size);
|
data->cvec.resize(params.size);
|
||||||
|
@ -1472,8 +1475,8 @@ struct DistStor
|
||||||
*/
|
*/
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
min_val = INT_MAX;
|
min_val = CounterLimits::max();
|
||||||
max_val = INT_MIN;
|
max_val = CounterLimits::min();
|
||||||
underflow = 0;
|
underflow = 0;
|
||||||
overflow = 0;
|
overflow = 0;
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
* Authors: Nathan Binkert
|
* Authors: Nathan Binkert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <cctype>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -117,12 +117,11 @@ inline bool
|
||||||
__to_number(string value, T &retval)
|
__to_number(string value, T &retval)
|
||||||
{
|
{
|
||||||
static const T maxnum = ((T)-1);
|
static const T maxnum = ((T)-1);
|
||||||
static const bool sign = maxnum < 0;
|
static const bool sign = numeric_limits<T>::is_signed;
|
||||||
static const int bits = sizeof(T) * 8;
|
static const int bits = numeric_limits<T>::digits;
|
||||||
static const T hexmax = maxnum & (((T)1 << (bits - 4 - sign)) - 1);
|
static const T hexmax = maxnum & (((T)1 << (bits - 4)) - 1);
|
||||||
static const T octmax = maxnum & (((T)1 << (bits - 3 - sign)) - 1);
|
static const T octmax = maxnum & (((T)1 << (bits - 3)) - 1);
|
||||||
static const T signmax =
|
static const T signmax = numeric_limits<T>::max();
|
||||||
(sign) ? maxnum & (((T)1 << (bits - 1)) - 1) : maxnum;
|
|
||||||
static const T decmax = signmax / 10;
|
static const T decmax = signmax / 10;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
Loading…
Reference in a new issue