* NAN and complex.h
@ 2007-09-18 21:52 TOMAZ
2007-09-18 22:21 ` Glynn Clements
2007-09-24 6:31 ` Lukasz Mielicki
0 siblings, 2 replies; 3+ messages in thread
From: TOMAZ @ 2007-09-18 21:52 UTC (permalink / raw)
To: linux-c-programming
Hi I made a program which basically averages data from a file. The data is
stored as complex float and I'm reading it with fread with no problem. Some
data are taged as NAN (at least ENVI, an image procesing soft read these
values as NAN). If I average the whole data adding a number with a NAN gives
me a NAN and my whole program fails.
What I did is the folowing which doesn't seems to work:
if(cabsf(zhhzhh)!= NAN)
{
printf("%f\n", cabsf(zhhzhh));
}
For some reason the test seeams to be positive all the time, I keep printing
NAN's ("nan" actualy).
Any idea?
Tomas
--
View this message in context: http://www.nabble.com/NAN-and-complex.h-tf4477349.html#a12766829
Sent from the linux-c-programming mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: NAN and complex.h
2007-09-18 21:52 NAN and complex.h TOMAZ
@ 2007-09-18 22:21 ` Glynn Clements
2007-09-24 6:31 ` Lukasz Mielicki
1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2007-09-18 22:21 UTC (permalink / raw)
To: TOMAZ; +Cc: linux-c-programming
TOMAZ wrote:
> Hi I made a program which basically averages data from a file. The data is
> stored as complex float and I'm reading it with fread with no problem. Some
> data are taged as NAN (at least ENVI, an image procesing soft read these
> values as NAN). If I average the whole data adding a number with a NAN gives
> me a NAN and my whole program fails.
>
> What I did is the folowing which doesn't seems to work:
>
> if(cabsf(zhhzhh)!= NAN)
> {
> printf("%f\n", cabsf(zhhzhh));
> }
>
> For some reason the test seeams to be positive all the time, I keep printing
> NAN's ("nan" actualy).
>
> Any idea?
NaN is not equal to anything, including itself.
To test for NaN, use isnan(). If you don't have isnan() (it's C99, not
C89), test whether "x != x" (true for NaN, false for everything else).
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: NAN and complex.h
2007-09-18 21:52 NAN and complex.h TOMAZ
2007-09-18 22:21 ` Glynn Clements
@ 2007-09-24 6:31 ` Lukasz Mielicki
1 sibling, 0 replies; 3+ messages in thread
From: Lukasz Mielicki @ 2007-09-24 6:31 UTC (permalink / raw)
To: linux-c-programming
> Hi I made a program which basically averages data from a file. The data is
> stored as complex float and I'm reading it with fread with no problem.
> Some
> data are taged as NAN (at least ENVI, an image procesing soft read these
> values as NAN). If I average the whole data adding a number with a NAN
> gives
> me a NAN and my whole program fails.
>
> What I did is the folowing which doesn't seems to work:
>
> if(cabsf(zhhzhh)!= NAN)
> {
> printf("%f\n", cabsf(zhhzhh));
> }
>
> For some reason the test seeams to be positive all the time, I keep
> printing
> NAN's ("nan" actualy).
>
> Any idea?
use isnan or isfinite to check for wrong values
BX
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-09-24 6:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-18 21:52 NAN and complex.h TOMAZ
2007-09-18 22:21 ` Glynn Clements
2007-09-24 6:31 ` Lukasz Mielicki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).