isnan() for complex data

J

jacob navia

Hi

Has C++ defined the function
isnan() for complex numbers?
What is the definition?

Thanks in advance
 
B

Barry

jacob said:
Hi

Has C++ defined the function
isnan() for complex numbers?
What is the definition?

Thanks in advance

/isnan/ is a macro in C99, still not in the current C++03 standard.

Synopsis:
#include <math.h>
int isnan(real-floating x);
 
J

jacob navia

Barry said:
/isnan/ is a macro in C99, still not in the current C++03 standard.

Synopsis:
#include <math.h>
int isnan(real-floating x);

In C99 this is ONLY defined for real types. No definition for
complex types. What is the definition in C++?

is it

insan(z) --> isnan(real(z) || isnan(imag(z)

or

insan(z) --> isnan(real(z) && isnan(imag(z)

???

The same problem appears for

isinf()
 
J

jacob navia

jacob said:
In C99 this is ONLY defined for real types. No definition for
complex types. What is the definition in C++?

is it

insan(z) --> isnan(real(z) || isnan(imag(z)

excuse me that should have been
> insan(z) --> isnan(real(z)) || isnan(imag(z))

with correctly matched parentheses!


or

insan(z) --> isnan(real(z) && isnan(imag(z)

The same
insan(z) --> isnan(real(z)) && isnan(imag(z))
 
C

ciccio

If you want to program an "isnan" function for std::complex<T>, then I
suggest you to use the above function.

If one of the parts is an invalid real number then your whole complex
number should be invalid.

The same reasoning goes for isinf. If one of your complex numbers is
infinite, then your complex number is one of the many representations of
infinite.

Klaas
 
B

Barry

jacob said:
excuse me that should have been


with correctly matched parentheses!




The same
insan(z) --> isnan(real(z)) && isnan(imag(z))
I think C++ will expand nothing but syntactic sugar(template function).

According to C++0x draft (here, N2315).

26.7 [c.math]

12
The templates defined in <cmath> replace the C99 macros with the same
names. The templates have the following
declarations:

....

template <class T> bool isnan(T x);

....

13
The templates behave the same as the C99 macros with corresponding names
defined in C99 subclause 7.12.3, Classification macros, and C99
subclause 7.12.14, Comparison macros.
SEE ALSO: ISO C subclauses 7.5, 7.10.2, 7.10.6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top