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

Discussion in 'C++' started by Dave Johansen, Jan 11, 2010.

  1. 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
     
    Dave Johansen, Jan 11, 2010
    #1
    1. Advertisements

  2. Dave Johansen

    Balog Pal Guest

    "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.


    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.
     
    Balog Pal, Jan 11, 2010
    #2
    1. Advertisements

  3. On Jan 11, 2:13 pm, "Balog Pal" <> wrote:
    > "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.

    >
    > 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
     
    Dave Johansen, Jan 11, 2010
    #3
  4. Dave Johansen

    James Kanze Guest

    On Jan 11, 8:56 pm, Dave Johansen <> wrote:
    > 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.

    --
    James Kanze
     
    James Kanze, Jan 12, 2010
    #4
  5. Dave Johansen

    Bo Persson Guest

    Paavo Helde wrote:
    > Dave Johansen <> wrote in
    > news::
    >
    >> On Jan 11, 2:13 pm, "Balog Pal" <> wrote:
    >>> "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.
    >>>
    >>> 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
    >>> mos

    >> t
    >>> 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 fo

    >> r
    >>> 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.

    >
    > 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
     
    Bo Persson, Jan 13, 2010
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Jalal
    Replies:
    13
    Views:
    4,322
    Jalal
    May 7, 2004
  2. Christopher

    std::numeric_limits::max()

    Christopher, Dec 9, 2004, in forum: C++
    Replies:
    1
    Views:
    12,982
    Alf P. Steinbach
    Dec 9, 2004
  3. puzzlecracker
    Replies:
    3
    Views:
    2,454
    Mike Wahler
    May 8, 2006
  4. liam_herron
    Replies:
    1
    Views:
    2,677
    Victor Bazarov
    Aug 1, 2006
  5. Replies:
    6
    Views:
    634
    Bo Persson
    Mar 7, 2007
  6. john
    Replies:
    4
    Views:
    665
    Chip Coldwell
    Nov 1, 2007
  7. Carsten Fuchs
    Replies:
    45
    Views:
    2,521
    James Kanze
    Oct 8, 2009
  8. Stuart Redmann
    Replies:
    3
    Views:
    1,610
    Victor Bazarov
    Jun 4, 2010
Loading...