What is permissable with HUGE_VAL

Arthur B. Smith art at dinorah.wustl.edu
Sun Jul 15 05:45:50 AEST 1990


Hello,

    I hope this hasn't already been discussed to death -- my reading
of this group has been somewhat spotty.  I am hoping for a
clarification on the Standard.  I have read the relevant part in
section 4.5 (p.112), but still have these questions.

    We have an array of doubles, and need to have a "flag value" in
some of the elements.  If the element has a flag value, then we don't
do anything more with it, otherwise we do.  We had hoped to use
HUGE_VAL as this flag value but upon reading the standard I have 
some questions, best expressed in code.

#include <math.h>
#include <stdio.h>

int main ( int argc, char * argv[] )

  {
  double    flag_val, ok_val, odd_val;

  flag_val = HUGE_VAL;	    /* Question 1: Is this legal? */
  ok_val = 5.2;
  if (flag_val == HUGE_VAL)
    puts("Question 2: Is this guaranteed to print?");
  if (ok_val < HUGE_VAL)
    puts("Question 3: Is this guaranteed to print?");
  odd_val = flag_val / 2.0; /* Question 4: Is this legal? */
  if (odd_val < HUGE_VAL)
    puts("Question 5a: Is this guaranteed to print?");
  else
    puts("Question 5b: Is this guaranteed to print?");
  return(0);
  }

My guesses are:
1) Yes
2) Yes
3) Yes
4) Yes
5a) No
5b) No  (One of 5a or 5b will print, but it is not guaranteed which)

    Is this right?

I guess further that if the above example used DBL_MAX instead of
HUGE_VAL (and included float.h) the answers would be
1) Yes
2) Yes
3) Yes
4) Yes
5a) Yes
6a) No (In fact, it is guaranteed not to print)

    Is this right?

    Please send responses by e-mail, since my reading is spotty.  I
will try to watch this newsgroup, though.  Thanks in advance!

    	-art smith  (art at dinorah.wustl.edu  or
    	    	     ...!uunet!wugate!dinorah!art)



More information about the Comp.std.c mailing list