I'm trying to check if a std::complex
number that is a result of a fourier transform (using http://fftw.org/) contains a NaN
in either the real or imag part.
I'm using Borland C++, so I don't have access to std::isnan
. I have tried to check if the number is NaN
by comparing it to itself:
(n.imag() != n.imag())
However, as soon as I call the n.imag()
or std::imag(n)
, I get a "floating point invalid operation".
Is there any way to validate if a std::complex
is good; if it contains a NaN
?
This works on g++ :
#include<iostream>
#include<cmath>
#include<complex>
int main(){
double x=sqrt(-1.);
std::complex<double> c(sqrt(-1.), 2.);
std::cout<<x<<"\n";
std::cout<<c<<"\n";
std::cout<< ( (c!=c) ? "yup" : "nope" )<<"\n";
}
From the float.h
header
int _isnan(double d);
Returns a nonzero
value (TRUE
) if the value passed in is a NaN; otherwise it returns 0
(FALSE
).
int _fpclass(double __d);
Returns an integer value that indicates the floating-point class of its argument. The possible values are defined in FLOAT.H (NaN, INF, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With