Walt Mankowski on 18 Aug 2004 14:18:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Re: How to specify NaN in C programs?


On Wed, Aug 18, 2004 at 07:55:50AM -0400, Jeff Abrahamson wrote:
> And if you want to stay compatible with C, you can always set it by
> dividing by zero:
> 
>     float f = 0.0 / 0.0;
> 
> You may have to fiddle with signals to avoid faulting, but I've
> certainly done this by accident. ;-)

Now you see, this highlights the inherent problems in doing this kind
of coding.  In theory, my function should only return values between 0
and 1, so I should be fine just setting it to -1 to mean "no value".
But I'm trying to be defensive, so I set it to NaN instead.  But what
if the code's broken and actually *does* divide by 0?

Sigh.

Since both events are unlikely, and since using NaN is causing me some
headaches, I'm thinking I'm better off just using -1 as a flag.

Walt

Attachment: signature.asc
Description: Digital signature