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

A

Alexander Malkis

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

Eric Sosman

Alexander said:
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.
 
R

Régis Troadec

Alexander Malkis said:
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
 
E

Eric Sosman

Régis Troadec said:
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.
 
B

Ben Pfaff

Régis Troadec said:
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.
 
I

Ike Naar

: 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).
 
R

Régis Troadec

Régis Troadec said:
"Alexander Malkis" <[email protected]> a écrit dans le
message de news:[email protected]...

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
 
R

Régis Troadec

Ike Naar said:
: 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
 
A

Alexander Malkis

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

Régis Troadec

Alexander Malkis said:
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
 
P

pete

Régis Troadec said:
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.
 

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,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top