[rational] Which way should std::numeric_limits::min go?

The default implementation of a std::numeric_limits<T> instantiation is to have all static data member be set to static_cast<X>(0) and all the static member functions return T{}. When an instantiation is manually written, you're supposed to leave members for the types of numbers (integer vs. floating vs...) that you're NOT as in the unimplemented case. The static member function "min" has a defect. The function "denorm_min" returns the smallest positive value that can be represented (denormalized or not), and is implemented only for floating types. The function "lowest," new to C++11, returns the regular (i.e. not Infinity or NaN, etc.) value closest to negative-infinity. Lowest was introduced because for C++98/03, "min" returned "denorm_min" for the built-in floating types and "lowest" for built-in integer types! You can't get generic code out of that (without checking some more flags from numeric_limits). Which version of "min" should boost::rational take? I was think of "denorm_min," since I'll be implementing that. The built-in integer types use "lowest" for "min," but don't define the other one at all. Daryle W.

The static member function "min" has a defect. The function "denorm_min" returns the smallest positive value that can be represented (denormalized or not), and is implemented only for floating types. The function "lowest," new to C++11, returns the regular (i.e. not Infinity or NaN, etc.) value closest to negative-infinity. Lowest was introduced because for C++98/03, "min" returned "denorm_min" for the built-in floating types and "lowest" for built-in integer types! You can't get generic code out of that (without checking some more flags from numeric_limits).
Which version of "min" should boost::rational take? I was think of "denorm_min," since I'll be implementing that. The built-in integer types use "lowest" for "min," but don't define the other one at all.
I would treat it as a variant of the integer types, and set min() to the most negative value, and max() to the most positive value. I suppose denorm_min could be the smallest positive value, but I don't think there's any prior art for that. HTH, John.

From: john@johnmaddock.co.uk Date: Thu, 22 Aug 2013 08:18:06 +0100
I would treat it as a variant of the integer types, and set min() to the most negative value, and max() to the most positive value. I suppose denorm_min could be the smallest positive value, but I don't think there's any prior art for that.
The only built-in types that define denorm_min use that function to define min, that's why I was thinking of using denorm_min for min too (instead of lowest, which the built-in integers use). I'm going to use some helper templates, since I'll have to use the component type's numeric_limits, and I'll have to specialize on signed vs. unsigned, bounded vs. unbounded, etc. Daryle W.
participants (2)
-
Daryle Walker
-
John Maddock