Motivation behind std::numeric_limits<float>::min()?

D

Dave Johansen

I was wondering if anyone could shed some light on why the min()
function from std::numeric_limits for floating point types is defined
as the positive number closest to 0 instead of the most negative
number like it is for integers. I did some Googling on the internet
and in this group and couldn't find anything that explained why the
decision was made for this to be the case.
Thanks,
Dave
 
B

Balog Pal

Dave Johansen said:
I was wondering if anyone could shed some light on why the min()
function from std::numeric_limits for floating point types is defined
as the positive number closest to 0 instead of the most negative
number like it is for integers. I did some Googling on the internet
and in this group and couldn't find anything that explained why the
decision was made for this to be the case.

Guess there was no fp implementations around, and not expected to born,
where the negative limit was different from -MAX. All the ones I know have
a sign bit. Integer representations OTOH have a different range on most
machines, having just one pattern for 0, thus an extra value in the
negatives...

For the other end, the smallest representable + value has little sense for
integrals, it will be 1 ;-) while it is important for floating point.

If you really wanted to ask why chose the function names that way instead of
distinct ones, I rather pass to others.
 
D

Dave Johansen

Guess there was no fp implementations around, and not expected to born,
where the negative limit was different from -MAX.  All the ones I know have
a sign bit.  Integer representations OTOH have a different range on most
machines, having just one pattern for 0, thus an extra value in the
negatives...

For the other end, the smallest representable + value has little sense for
integrals, it will be 1 ;-)  while it is important for floating point.

If you really wanted to ask why chose the function names that way instead of
distinct ones, I rather pass to others.

That makes sense and the best guess I've heard so far was to maintain
"compatibility" with the C values *_MIN/*_MAX, but I really don't see
the logic in that since having two distinct definitions based on type
breaks the templated/abstraction metaphor that is used in
std::numeric_limits.

But was "compatibility" really the driving influence behind the
decision, because that seems like a case of failed logic to me.

Dave
 
J

James Kanze

I was wondering if anyone could shed some light on why the
min() function from std::numeric_limits for floating point
types is defined as the positive number closest to 0 instead
of the most negative number like it is for integers.

History.
 
B

Bo Persson

Paavo said:
I have struggled with this as well. I have hard time to imagine a
templated function designed to work with both integers and floating
point types, and using std::numeric_limits<T>::min() in the same
place of the algorithm. I always ended up with some
specializations, but this is something one may easily overlook.

In C++0x, will there be a std::numeric_limits<T>::real_min()?

It is called lowest(), but otherwise - Yes.


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top