faq 1.#QNAN00000000 and -1.#IND000000000

F

fcvcnet

Hi,
I got result 1.#QNAN00000000 and -1.#IND000000000 in my programme, what
happened?
why?
Thanks.
 
K

Kavya

fcvcnet said:
Hi,
I got result 1.#QNAN00000000 and -1.#IND000000000 in my programme, what
happened?
why?

If you can post your code then it might be more easy to find the
problem.
 
J

Jim Langston

fcvcnet said:
Hi,
I got result 1.#QNAN00000000 and -1.#IND000000000 in my programme, what
happened?
why?
Thanks.

NAN is not a number. This can happen with a floating point math won't work.
In some cases dividing by 0 will produce a NAN, but in others it produces
infinity (not sure if the specs say whiat it should produce).

Not sure what IND is. It may be infinity, but I would think that would be
INF, so I'm not sure.
 
M

Marcus Kwok

Jim Langston said:
NAN is not a number. This can happen with a floating point math won't work.
In some cases dividing by 0 will produce a NAN, but in others it produces
infinity (not sure if the specs say whiat it should produce).

Not sure what IND is. It may be infinity, but I would think that would be
INF, so I'm not sure.

I'm not sure either, but IND might mean "indeterminate". As in,
(informally) 1/0 is infinity but 0/0 is indeterminate.

http://mathworld.wolfram.com/Indeterminate.html
 
G

Geo

fcvcnet said:
Hi,
I got result 1.#QNAN00000000 and -1.#IND000000000 in my programme, what
happened?
why?
Thanks.

recently I had to do some experimentation with this stuff, here's some
code and the output


float pinf = std::numeric_limits<float>::infinity();
double dpinf = std::numeric_limits<double>::infinity();

float ninf = -std::numeric_limits<float>::infinity();
float zero = 0.0;
float NaN = std::numeric_limits<float>::quiet_NaN();
float nNaN = -std::numeric_limits<float>::quiet_NaN();
double dNaN = std::numeric_limits<double>::quiet_NaN();

float xNaN = static_cast<float>(dNaN);

std::cout << "+ve infinity " << pinf << "\n";
std::cout << "-ve infinity " << ninf << "\n";
std::cout << "+ve QNAN " << NaN << "\n";
std::cout << "+ve dQNAN " << dNaN << "\n";
std::cout << "+ve xQNAN " << xNaN << "\n";
std::cout << "-ve QNAN " << nNaN << "\n";
std::cout << "+inf = +inf " << (pinf == pinf) << "\n";
std::cout << "+inf <= +inf " << (pinf <= pinf) << "\n";
std::cout << "+inf = +dinf " << (pinf == dpinf) << "\n";
std::cout << "+inf = -inf " << (pinf == ninf) << "\n";
std::cout << "+inf / +inf " << pinf/pinf << "\n";
std::cout << "+inf / -inf " << pinf/ninf << "\n";
std::cout << "+inf / zero " << pinf/zero << "\n";
std::cout << "+inf * -inf " << pinf*ninf << "\n";
std::cout << "+inf + -inf " << pinf+ninf << "\n";
std::cout << "+inf + +inf " << pinf+pinf << "\n";
std::cout << "+inf - -inf " << pinf-ninf << "\n";
std::cout << "+inf - +inf " << pinf-pinf << "\n";
std::cout << "-inf - -inf " << ninf-ninf << "\n";
std::cout << "\n\n";
std::cout << "NaN = NaN " << (NaN == NaN) << "\n";
std::cout << "-NaN = -NaN " << (nNaN == nNaN) << "\n";
std::cout << "-NaN = NaN " << (nNaN == NaN) << "\n";
std::cout << "NaN = -NaN " << (NaN == nNaN) << "\n";
std::cout << "NaN = +inf " << (NaN == pinf) << "\n";
std::cout << "NaN = -inf " << (NaN == ninf) << "\n";
std::cout << "0 / zero " << 0/zero << "\n";

+ve infinity 1.#INF
-ve infinity -1.#INF
+ve QNAN 1.#QNAN
+ve dQNAN 1.#QNAN
+ve xQNAN 1.#QNAN
-ve QNAN -1.#IND
+inf = +inf 1
+inf <= +inf 1
+inf = +dinf 1
+inf = -inf 0
+inf / +inf -1.#IND
+inf / -inf -1.#IND
+inf / zero 1.#INF
+inf * -inf -1.#INF
+inf + -inf -1.#IND
+inf + +inf 1.#INF
+inf - -inf 1.#INF
+inf - +inf -1.#IND
-inf - -inf -1.#IND


NaN = NaN 0
-NaN = -NaN 0
-NaN = NaN 0
NaN = -NaN 0
NaN = +inf 0
NaN = -inf 0
0 / zero -1.#IND
 
G

Geo

Meant to say, results are from gcc on pentium, and seem to agree with
IEEE 754. VC 6.0 results differ for some cases, VC 7.0 is the same as
gcc.
 
F

fcvcnet

Thanks you very much.

Jim Langston said:
NAN is not a number. This can happen with a floating point math won't
work. In some cases dividing by 0 will produce a NAN, but in others it
produces infinity (not sure if the specs say whiat it should produce).

Not sure what IND is. It may be infinity, but I would think that would be
INF, so I'm not sure.
 
C

cts

Odd that no one seems to have brought up errno.

When something in the C libraries, like the math library, fails, the
global variable errno is set. If you get a value of #QNAN or #IND,
it's likely that an error in the standard math library. You can easily
check this after an operation and you can get a nice string
representation of the error message too.

example:

#include <cmath>
#include <cstring>
#include <iostream>

errno = 0; // clear out any previous errors

// example math call
y = std::atan(x); // we suspect that something screwy happens here,
maybe 'x' is a bad value

// check if there was a catastrophe, if yes, print out the error
message
if (errno)
std::cout << strerror(errno) << std::endl;
 
F

fcvcnet

Thanks you very much.

cts said:
Odd that no one seems to have brought up errno.

When something in the C libraries, like the math library, fails, the
global variable errno is set. If you get a value of #QNAN or #IND,
it's likely that an error in the standard math library. You can easily
check this after an operation and you can get a nice string
representation of the error message too.

example:

#include <cmath>
#include <cstring>
#include <iostream>

errno = 0; // clear out any previous errors

// example math call
y = std::atan(x); // we suspect that something screwy happens here,
maybe 'x' is a bad value

// check if there was a catastrophe, if yes, print out the error
message
if (errno)
std::cout << strerror(errno) << std::endl;
 
F

fcvcnet

#include "stdafx.h"
#include <cmath>
#include <cstring>
#include <iostream>

int main(int argc, char* argv[])
{
errno = 0;
double i,j;
i=1;
j=0;
double y = i/j;
if (errno)
std::cout << strerror(errno) << std::endl;
std::cin >> i;
return 0;
}
I tried , but I saw nothing. My code right?
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top