[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9378.0. "ieee floating point warning?" by RDGENG::CHAMBERLIN (Danger! Do not Reverse Polarity) Thu Apr 03 1997 09:02

Can anyone please explain why the following program:

#include <stdlib.h>
#include <math.h>

int main (int argc, char **argv)
{
  double	foo;

  foo = HUGE_VAL;

  return 0;
}

when compiled with the -ieee flag gives a warning:

cc: Warning: foo.c, line 8: In this statement, a floating point error occurs in 
evaluating the expression "1.8e308".
  foo = HUGE_VAL;
--------^

but doesn't when compiled without?

I note from maths.h that different values are included for HUGE_VAL, but I'm not
sure why the warning.

Thanks,

		Ian Chamberlin,

			Software Partner Engineering.

T.RTitleUserPersonal
Name
DateLines
9378.1with -ieee, HUGE_VAL is +infinity HYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Thu Apr 03 1997 10:589
My analysis (from looking at the .lis file) shows that when compiled
with -ieee, HUGE_VAL is +infinity (0x7ff0000000000000).

The compiler does the assignment correctly, but issues a warning that the
value isn't a valid number.

If they want the largest valid number, use DBL_MAX instead of HUGE_VAL.

								-- Chuck Newman
9378.2HUGE_VAL is +Infinity in -ieee modeSUBPAC::FARICELLIThu Apr 03 1997 11:0814
   Apparently the author of math.h intended for HUGE_VAL to be +Infinity
   when compiled in full ieee floating point mode; and the maximum
   finite double value if not.

   One way to get a +Infinity is to use a number larger than the
   maximum (1.8e308 will do this), but this makes the compiler issue
   a warning about exceeding the range of a double, even in
   -ieee_with_no_inexact (-ieee) mode. Should it?

   If you want the values of the maximum finite for double/float,
   see /usr/include/float.h (FLT_MAX, DBL_MAX).

   -- John Faricelli
9378.3Fixed in SteelSMURF::GAFJerry Feldman, Unix Dev. Environment, DTN:381-2970Thu Apr 03 1997 17:1120
    HUGE_VAL is required to be +Infinity in IEEE mode and DBL_MAX when not
    in IEEE mode. The compiler warning has been with us since day 1 (eg.
    Silver SSB). 
    
    In Steel, I change HUGE_VAL to point to the libc infinity value.
    #if defined(_IEEE_FP)
    extern  unsigned   int __DINFINITY[2];
    #	define HUGE_VAL (*((double *) (__DINFINITY)))
    #else
    #	define HUGE_VAL 1.797693134862315708e308
    #endif
    
    This will suppress the warning, but could cause compilation errors in
    some programs that initialize variables to HUGE_VAL. 
    
    In IEEE mode, all math functions that return HUGE_VAL return +/-
    infinity.
    
    Both the old C compiler, CFE, and the new C compiler, DECC, issue the
    warning. 
9378.4VESPER::VESPEROpenGL Alpha GeekThu Apr 03 1997 17:3617
>    In Steel, I change HUGE_VAL to point to the libc infinity value.
>    #if defined(_IEEE_FP)
>    extern  unsigned   int __DINFINITY[2];
>    #	define HUGE_VAL (*((double *) (__DINFINITY)))
>    #else
>    #	define HUGE_VAL 1.797693134862315708e308
>    #endif
>    
>    This will suppress the warning, but could cause compilation errors in
>    some programs that initialize variables to HUGE_VAL. 

Ouch!

Correct according to the standard (``positive double expression''), but
I'd still rather see a constant expression.

Andy V
9378.5SMURF::GAFJerry Feldman, Unix Dev. Environment, DTN:381-2970Fri Apr 04 1997 15:013
    re: .4
    Unfortunately, there is no way to put a constant in there and not have
    a compiler warning. Both CFE and DECC will generate a warning. 
9378.6RDGENG::CHAMBERLINDanger! Do not Reverse PolarityMon Apr 07 1997 06:0110
Thanks for the discussion - I didn't expect a simple query to generate so much!

re .3 and .4, 

Personally I think I'd rather see a warning than have unexpailned errors later
on, but I guess we have to stick with the standards.

What do other suppliers do in this case?

/Ian 
9378.7AIX, SUNOS, HPSMURF::GAFJerry Feldman, Unix Dev. Environment, DTN:381-2970Mon Apr 07 1997 12:0116
    IBM AIX references a double value:
    #ifdef _ANSI_C_SOURCE
    
    extern  unsigned _DBLINF[2];
    
    #define HUGE_VAL (*((double *)(_DBLINF)))
    
    
    --------------------
    SunOS:
    #define HUGE_VAL __huge_val._d
    
    --------------------
    HP_UX uses a constant equivalent to the MAX_DOUBLE.