max{f | f is a float and -f is a float and doesn't cause overflow}== ?

Discussion in 'C Programming' started by Alexander Malkis, Apr 13, 2004.

  1. What is the biggest float number f so that -f doesn't overflow and is
    still representable as a float.

    --
    Best regards,
    Alex.

    PS. To email me, remove "loeschedies" from the email address given.
    Alexander Malkis, Apr 13, 2004
    #1
    1. Advertising

  2. Alexander Malkis

    Eric Sosman Guest

    Re: max{f | f is a float and -f is a float and doesn't cause overflow}==?

    Alexander Malkis wrote:
    >
    > What is the biggest float number f so that -f doesn't overflow and is
    > still representable as a float.


    FLT_MAX, defined in <float.h>. This value will be
    different on different C implementations, but will always
    be at least 1e37.

    --
    Eric Sosman, Apr 13, 2004
    #2
    1. Advertising

  3. Re: max{f | f is a float and -f is a float and doesn't cause overflow} == ?

    "Alexander Malkis" <-sb.de> a écrit dans le
    message de news:c5gug3$a3au$-saarland.de...
    > What is the biggest float number f so that -f doesn't overflow and is
    > still representable as a float.


    The <float.h> header provides lots of stuff concerning floating-point
    numbers handling. The macros FLT_MIN and FLT_MAX represent the largest
    values respectively for the minimum et maximum values for the type float.
    The values are implementation defined.
    Therefore, to anwer your question, if f is positive, -f doesnt overflow
    until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow until
    f doesn't exceed -FLT_MAX.

    Regis

    >
    > --
    > Best regards,
    > Alex.
    >
    > PS. To email me, remove "loeschedies" from the email address given.
    Régis Troadec, Apr 13, 2004
    #3
  4. Alexander Malkis

    Eric Sosman Guest

    "Régis Troadec" wrote:
    >
    > "Alexander Malkis" <-sb.de> a écrit dans le
    > message de news:c5gug3$a3au$-saarland.de...
    > > What is the biggest float number f so that -f doesn't overflow and is
    > > still representable as a float.

    >
    > The <float.h> header provides lots of stuff concerning floating-point
    > numbers handling. The macros FLT_MIN and FLT_MAX represent the largest
    > values respectively for the minimum et maximum values for the type float.
    > The values are implementation defined.
    > Therefore, to anwer your question, if f is positive, -f doesnt overflow
    > until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow until
    > f doesn't exceed -FLT_MAX.


    No; you've misunderstood FLT_MIN:

    5.2.4.2.2 Characteristics of floating types <float.h>
    [...]
    /10/ The values given in the following list shall be
    replaced by constant expressions with implementation-
    defined (positive) values that are less than or equal
    to those shown:
    [...]
    -- minimum normalized positive floating-point number,
    [...]
    FLT_MIN 1E-37

    IMHO the name FLT_MIN is misleading on two counts. First,
    it looks just like INT_MIN and LONG_MIN and so forth, but has
    a meaning that is not at all analogous to those. Second, it
    is not necessarily the minimum positive value distinguishable
    from 0.0f; an implementation that supports "denormal" numbers
    (most do, nowadays) can represent values that are smaller than
    FLT_MIN but greater than zero. Misleading or not, though, the
    name is part of the Standard and we'll just have to deal with
    it by remembering what it isn't.

    --
    Eric Sosman, Apr 13, 2004
    #4
  5. Alexander Malkis

    Ben Pfaff Guest

    Re: max{f | f is a float and -f is a float and doesn't causeoverflow} == ?

    "Régis Troadec" <> writes:

    > Therefore, to anwer your question, if f is positive, -f doesnt overflow
    > until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow until
    > f doesn't exceed -FLT_MAX.


    FLT_MIN has little or nothing to do with overflow. It is the
    minimum normalized positive float. Its value is greater than 0
    and less than or equal to 1e-37.
    --
    Just another C hacker.
    Ben Pfaff, Apr 13, 2004
    #5
  6. Alexander Malkis

    Ike Naar Guest

    Re: max{f | f is a float and -f is a float and doesn't cause overflow} == ?

    "Regis Troadec" <> wrote:
    : The <float.h> header provides lots of stuff concerning floating-point
    : numbers handling. The macros FLT_MIN and FLT_MAX represent the largest
    : values respectively for the minimum et maximum values for the type float.
    : The values are implementation defined.
    : Therefore, to anwer your question, if f is positive, -f doesnt overflow
    : until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow until
    : f doesn't exceed -FLT_MAX.

    Methinks you're mixing up FLT_MIN (tiny, positive) and -FLT_MAX (huge, negative).

    --
    mail to ike at iae dot nl
    Ike Naar, Apr 13, 2004
    #6
  7. Re: max{f | f is a float and -f is a float and doesn't cause overflow} == ?

    "Régis Troadec" <> a écrit dans le message de
    news:c5h1g2$2pi$...
    >
    > "Alexander Malkis" <-sb.de> a écrit dans

    le
    > message de news:c5gug3$a3au$-saarland.de...
    > > What is the biggest float number f so that -f doesn't overflow and is
    > > still representable as a float.

    >
    > The <float.h> header provides lots of stuff concerning floating-point
    > numbers handling. The macros FLT_MIN and FLT_MAX represent the largest
    > values respectively for the minimum et maximum values for the type float.
    > The values are implementation defined.
    > Therefore, to anwer your question, if f is positive, -f doesnt overflow
    > until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow

    until
    > f doesn't exceed -FLT_MAX.


    Arghhh, BULLSHIT !! Some confusion : I answered as if it were with integers.
    Not the same.

    FLT_MAX is only useful.

    Regis

    >
    > Regis
    >
    > >
    > > --
    > > Best regards,
    > > Alex.
    > >
    > > PS. To email me, remove "loeschedies" from the email address given.

    >
    >
    Régis Troadec, Apr 13, 2004
    #7
  8. Re: max{f | f is a float and -f is a float and doesn't cause overflow} == ?

    "Ike Naar" <> a écrit dans le message de
    news:4fUec.1391$%...
    > "Regis Troadec" <> wrote:
    > : The <float.h> header provides lots of stuff concerning floating-point
    > : numbers handling. The macros FLT_MIN and FLT_MAX represent the largest
    > : values respectively for the minimum et maximum values for the type

    float.
    > : The values are implementation defined.
    > : Therefore, to anwer your question, if f is positive, -f doesnt overflow
    > : until f doesn't exceed -FLT_MIN, if f is negative, -f doesnt overflow

    until
    > : f doesn't exceed -FLT_MAX.
    >
    > Methinks you're mixing up FLT_MIN (tiny, positive) and -FLT_MAX (huge,

    negative).

    In fact, I really misunderstood it as Eric and Ben said. I answered too
    quickly as if it were integers and had some confusion between FLT_MIN and
    INT_MIN.

    Regis

    >
    > --
    > mail to ike at iae dot nl
    Régis Troadec, Apr 13, 2004
    #8
  9. Re: max{i | f is an int and -i is an int and doesn't cause overflow}== ?

    And how about an int? On my impl, one of -INT_MIN and -INT_MAX is not
    representable.

    --
    Best regards,
    Alex.

    PS. To email me, remove "loeschedies" from the email address given.
    Alexander Malkis, Apr 14, 2004
    #9
  10. Re: max{i | f is an int and -i is an int and doesn't cause overflow} == ?

    "Alexander Malkis" <-sb.de> a écrit dans le
    message de news:c5hs15$b1v0$-saarland.de...
    > And how about an int? On my impl, one of -INT_MIN and -INT_MAX is not
    > representable.


    The absolutes values of INT_MIN and INT_MAX may be different, so
    either -INT_MIN either -INT_MAX isn't representable. Often, the absolute
    value of the minimum is greater than the absolute value of the maximum
    (perhaps because of 2's complement ?), then, -INT_MIN may not be
    representable on your implementation, because it's greater than INT_MAX.

    The bullshits I said about floating point numbers can now be applied to
    integers ;-)
    If an int, say n, is negative, then -n is representable if it (-n) doesn't
    exceed INT_MAX.
    If n is positive, then -n is representable if it doesn't exceed INT_MIN.

    The header <limits.h> provides all you need to safely control the values of
    your integers.
    According to the type of your signed integers, other useful macros are
    SCHAR_MIN(MAX) for signed char, SHRT_MIN(MAX) for short int, LONG_MIN(MAX)
    for long int, and in C99, LLONG_MIN(MAX) for long long int.

    Regis

    >
    > --
    > Best regards,
    > Alex.
    >
    > PS. To email me, remove "loeschedies" from the email address given.
    Régis Troadec, Apr 14, 2004
    #10
  11. Alexander Malkis

    pete Guest

    Re: max{i | f is an int and -i is an int and doesn't cause overflow} == ?

    Régis Troadec wrote:

    > If an int, say n, is negative,
    > then -n is representable if it (-n) doesn't exceed INT_MAX.
    > If n is positive,
    > then -n is representable if it doesn't exceed INT_MIN.


    If n is positive,
    then there's no problem with -n exceeding any limits.

    --
    pete
    pete, Apr 14, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bd
    Replies:
    0
    Views:
    614
  2. semut
    Replies:
    3
    Views:
    396
    Binary
    Dec 1, 2006
  3. Summercool
    Replies:
    9
    Views:
    878
    dorayme
    Oct 23, 2007
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,525
    James Kanze
    Oct 8, 2009
  5. Greg Ferris

    Textarea max rows and max characters per row

    Greg Ferris, Jan 16, 2004, in forum: Javascript
    Replies:
    2
    Views:
    576
    Greg Ferris
    Jan 16, 2004
Loading...

Share This Page