Re: Maximum range of double.
On 19 Mrz., 08:35, Seungbeom Kim <musip...@bawi.org> wrote:
This makes min() and max() of std::numeric_limits crippled, if
not useless; you have to deal with different cases yourself:
T max =
#if -infinity is desired /* which is not essential but often nice
if there is one available */
std::numeric_limits<T>::has_infinity ?
-std::numeric_limits<T>::infinity() :
#endif
!std::numeric_limits<T>::is_integer ?
-std::numeric_limits<T>::max() :
std::numeric_limits<T>::min();
This is an unnecessary complication for the programmer.
I whole-heartly agree with you.
I'm not even sure whether checking is_integer only gives the correct
result; 18.2.1.2/2 says "For floating types with denormalization,
returns the minimum positive normalized value," which seems to imply
that I also have to consider has_denorm. Which leads me even more into
the details of the standardese and/or the implementation.
I don't think that you have to check for has_denom in this
case, because std::numeric_limits<FP>::max() (FP: floating point
type) must always be larger than any possible denormalized number.
This implies that the same is true for -
std::numeric_limits<FP>::max()
in the absolute sense.
An interesting programmatic challenge would be the need to check
whether the corresponding type is bounded or not, see the remark
"Meaningful for all specializations in which is_bounded != false, or
is_bounded == false && is_signed == false."
In this situation the above test will not work and could not be
written
in a reasonable way other than by using a non-number like a NaN
as initial value (if such thingee exists for this type).
This would also lead to ordering problems in the comparison and
one might consider to simply use the first item of the sequence as
initial value (if such exists - empty sequence).
Furthermore, the standard doesn't seem to say anywhere that -max() is
the minimum finite value for floating-point types. I can imagine another
complication that would arise if one would want to create a new numeric
type that has asymmetric ranges for positive and negative values, though
this is not a very realistic example.
I think that this is a reasonable point to consider.
I think we should at least have a new function that returns the true
minimum value regardless of whether the type is floating-point or not.
I agree.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]