Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.c

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2012, 09:58 PM
Fred K
Guest
 
Posts: n/a
Default Float constant

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?

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 05-08-2012, 10:37 PM
James Kuyper
Guest
 
Posts: n/a
Default Re: Float constant

On 05/08/2012 05:58 PM, Fred K wrote:
> 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?
Reply With Quote
  #3 (permalink)  
Old 05-09-2012, 12:43 AM
Barry Schwarz
Guest
 
Posts: n/a
Default Re: Float constant

On Tue, 8 May 2012 14:58:59 -0700 (PDT), Fred K
<fred.l.kleinschmidt@gmail.com> wrote:

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

--
Remove del for email
Reply With Quote
  #4 (permalink)  
Old 05-09-2012, 06:52 AM
Fred J. Tydeman
Guest
 
Posts: n/a
Default Re: Float constant

On Tue, 8 May 2012 21:58:59 UTC, Fred K <fred.l.kleinschmidt@gmail.com> wrote:

> 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
tydeman@tybor.com 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.
Reply With Quote
  #5 (permalink)  
Old 05-15-2012, 11:45 AM
James Kuyper
Guest
 
Posts: n/a
Default Re: Float constant

On 05/09/2012 05:11 PM, Fred K wrote:
> On Tuesday, May 8, 2012 3:37:43 PM UTC-7, James Kuyper wrote:
>> On 05/08/2012 05:58 PM, Fred K wrote:
>>> 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?

>
> 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).
--
James Kuyper
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 07:51 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.