Float constant

F

Fred K

Compiling in 32-bit mode on an HP (RISC), this statement:
float val = 1.1E-38F;
causes this warning message:
Warning 602: Float constant exceeds its storage.

If I remove the trailing "F", there is no warning, and the stored value is correct.
I can set it to 1.1E-45 (note no "F") with no warning, and it prints out correctly. MINFLOAT is 1.40129846432481707e-45

Why does specifying the constant with a float flag (F) cause this warning?
 
J

James Kuyper

Compiling in 32-bit mode on an HP (RISC), this statement:
float val = 1.1E-38F;
causes this warning message:
Warning 602: Float constant exceeds its storage.

If I remove the trailing "F", there is no warning, and the stored value is correct.
I can set it to 1.1E-45 (note no "F") with no warning, and it prints out correctly. MINFLOAT is 1.40129846432481707e-45

Why does specifying the constant with a float flag (F) cause this warning?

The C standard defines no such thing as MINFLOAT. What is the value of
FLT_MIN?
 
B

Barry Schwarz

Compiling in 32-bit mode on an HP (RISC), this statement:
float val = 1.1E-38F;
causes this warning message:
Warning 602: Float constant exceeds its storage.

If I remove the trailing "F", there is no warning, and the stored value is correct.
I can set it to 1.1E-45 (note no "F") with no warning, and it prints out correctly. MINFLOAT is 1.40129846432481707e-45

Why does specifying the constant with a float flag (F) cause this warning?

Because the F changes the constant from a double to a float. The
message occurs because the minimum exponent for a float on your system
is apparently something more than -37 (most systems will represent
1.1e-38 as .11e-37 but not IBM mainframes) while the minimum exponent
for a double is quite a bit less.
 
F

Fred J. Tydeman

Compiling in 32-bit mode on an HP (RISC), this statement:
float val = 1.1E-38F;
causes this warning message:
Warning 602: Float constant exceeds its storage.

If I remove the trailing "F", there is no warning, and the stored value is correct.
I can set it to 1.1E-45 (note no "F") with no warning, and it prints out correctly. MINFLOAT is 1.40129846432481707e-45

Why does specifying the constant with a float flag (F) cause this warning?

Because 1.4e-45 < 1.1e-38 < 1.17e-38, or in symbols from C11
FLT_TRUE_MIN < 1.1e-38 < FLT_MIN
So, the value you are using (1.1e-38) is a subnormal or denormal number
and cannot be represented will full precision. Their warning message
could be improved.
---
Fred J. Tydeman Tydeman Consulting
(e-mail address removed) Testing, numerics, programming
+1 (775) 358-9748 Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.
 
J

James Kuyper

FLT_MIN is 1.17549435e-38.
The error message really comes from using
float x = 1.1754943508e-38F

Then why did you tell us it came from

float val = 1.1E-38F;

? When you go to the doctor, and your wrist hurts, are you in the habit
of telling him that your finger hurts? Your misrepresentation about the
cause of the warning message caused Barry Schwarz an Fred Tydeman to
mis-diagnose the problem.
This is (slightly) larger than FLT_MIN, but both print out as
1.1754943508222875003e-38. I presume this latter number is the
closest value that FLT_MIN represents; one bit larger would be a
number that is larger than 1.17549435e-38, and further
away.

That makes an important difference; 1.1E-38F is less than FLT_MIN on
most systems, yours included. That means it can't be represented as a
normalized floating point value. If that had been the reason for the
warning, it was very badly worded, but it would have been a reasonable
thing to warn about.

However, since your actual number is larger than FLT_MIN, my best guess
is that it's warning you about the fact that your constant has three
more digits than the maximum that can be meaningful for your system.
That's not a particularly important issue to warn about, but it is not
wholly unreasonable to warn about it. If that's the case, it's still a
badly worded message. That would explain why the message goes away if
you remove the 'F'; the maximum number of meaningful digits for double
is typically roughly double the number for float. Notice that it was
impossible for any of us to make such a guess based upon your original
message, where the number had only two significant digits.

Because the warning message is such a poor fit to either guess, it's
still possible that some other problem is the real cause. I'd recommend
contacting someone knowledgeable about the particular compiler which
your using, preferably the compiler vendor's official customer support.
And when you contact them, please give them the correct code.
Preferably, a complete program, as small as possible, that demonstrates
the problem (and test it before sending it to them, to make sure it
actually demonstrates the problem).
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top