nans or infinities as data 
Author Message
 nans or infinities as data

Hello c.l.c.m-ers

I often find myself in a situation where a struct
has several float/double entries which may or may
not be assigned, and I'd like to know when they
have been assigned. Rather that have a flag

struct
{
  double value;
  char   value_has_been_assigned;
  :
  :

Quote:
}

which is set on assignment, I'd like to initilise the
values to an "unassigned" value.

When the data must be positive this is easy -- I use a
zero. Is it safe/portable/efficient to use a NaN or Inf
in this way?

Thanks

-j
--
J.J.Green, Dept. Applied Math. University of Sheffield, UK
http://www.*-*-*.com/
--



Tue, 14 Jan 2003 03:00:00 GMT  
 nans or infinities as data

Quote:

> Is it safe/portable/efficient to use a NaN or Inf
> in this way?

Not every environment that supports C supports those
"IEEE floating-point" extensions.  You might try using
HUGE_VAL from <math.h>, which will be an infinity or
else the largest representable value, which has little
chance of occurring in any correct computation.
--



Wed, 15 Jan 2003 03:00:00 GMT  
 nans or infinities as data

Quote:

>I often find myself in a situation where a struct
>has several float/double entries which may or may
>not be assigned, and I'd like to know when they
>have been assigned. Rather that have a flag

>struct
>{
>  double value;
>  char   value_has_been_assigned;
>  :
>  :
>}

>which is set on assignment, I'd like to initilise the
>values to an "unassigned" value.

>When the data must be positive this is easy -- I use a
>zero. Is it safe/portable/efficient to use a NaN or Inf
>in this way?

It seems like a reasonable idea, but it's not guaranteed
to be portable because implementations aren't required
to support NaN or Inf.  (At least they weren't under the
old standard, which is what most current compilers are
based on.)

-- Gary Culp
--



Wed, 15 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Infinity and NaNs

2. Is infinity equal to infinity?

3. NANs and INFs

4. NaNs and intinities

5. IEEE, ANSI, INFs, and NaNs

6. Quiet NaNs, release mode and debug mode

7. NaNs and IEEE arithmetic

8. NaNs, Infs, and all that

9. Test for infinity?

10. infinity loop?

11. NAN, +/- Infinity

12. C Float multiplication infinity validation!

 

 
Powered by phpBB® Forum Software