Skip to main content
update formatting for inline variables - use inline code spans to avoid HTML stripping of invalid tags (e.g. "<T>" interpreted as HTML tag)
Source Link

Was my decision to make lowerlimitlowerlimit and upperlimitupperlimit public the correct one?

Since lowerlimitlowerlimit and upperlimitupperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest()numeric_limits<T>::lowest() correctly?

You are right. For float, double, they are symmetrical in sign. the lowest for float and double are:

float   -FLT_MAX
double  -DBL_MAX

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest() correctly?

You are right. For float, double, they are symmetrical in sign. the lowest for float and double are:

float   -FLT_MAX
double  -DBL_MAX

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits<T>::lowest() correctly?

You are right. For float, double, they are symmetrical in sign. the lowest for float and double are:

float   -FLT_MAX
double  -DBL_MAX
deleted 282 characters in body
Source Link
phy nju
  • 310
  • 1
  • 7

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest() correctly?

You are right. For float, double, they are symmetrical in sign. the lowest for float and double are:

/** Implementation of numeric_limits<T>::lowest from C++11 `std`. Returns the most
negative value that can be represented by the type T. */
template <typename T, typename Enable = void>
struct numeric_limits {
    static T lowest() {
      float  return std::numeric_limits<T>::min();-FLT_MAX
  double  }
};-DBL_MAX

I would just use std::numeric_limits::min(), I do not understand why you use -std::numeric_limits::max(). Say, if T is unsigned, then -max() is wrong.

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest() correctly?

/** Implementation of numeric_limits<T>::lowest from C++11 `std`. Returns the most
negative value that can be represented by the type T. */
template <typename T, typename Enable = void>
struct numeric_limits {
    static T lowest() {
        return std::numeric_limits<T>::min();
    }
};

I would just use std::numeric_limits::min(), I do not understand why you use -std::numeric_limits::max(). Say, if T is unsigned, then -max() is wrong.

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest() correctly?

You are right. For float, double, they are symmetrical in sign. the lowest for float and double are:

float   -FLT_MAX
double  -DBL_MAX
Source Link
phy nju
  • 310
  • 1
  • 7

Was my decision to make lowerlimit and upperlimit public the correct one?

Since lowerlimit and upperlimit are only written by constructor. you can make then const. So even though they are public access, still safe.

Did I handle the implementation of numeric_limits::lowest() correctly?

/** Implementation of numeric_limits<T>::lowest from C++11 `std`. Returns the most
negative value that can be represented by the type T. */
template <typename T, typename Enable = void>
struct numeric_limits {
    static T lowest() {
        return std::numeric_limits<T>::min();
    }
};

I would just use std::numeric_limits::min(), I do not understand why you use -std::numeric_limits::max(). Say, if T is unsigned, then -max() is wrong.