# faq 1.#QNAN00000000 and -1.#IND000000000

Discussion in 'C++' started by fcvcnet, Nov 1, 2006.

1. ### fcvcnetGuest

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

fcvcnet, Nov 1, 2006

2. ### KavyaGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

fcvcnet wrote:
> 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.

Kavya, Nov 1, 2006

3. ### Jim LangstonGuest

"fcvcnet" <> wrote in message
news:ei9ndm\$5lf\$99.com...
> 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.

Jim Langston, Nov 1, 2006
4. ### Marcus KwokGuest

Jim Langston <> wrote:
> "fcvcnet" <> wrote in message
> news:ei9ndm\$5lf\$99.com...
>> 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.

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

--
Marcus Kwok
Replace 'invalid' with 'net' to reply

Marcus Kwok, Nov 1, 2006
5. ### GeoGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

fcvcnet wrote:
> 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

Geo, Nov 1, 2006
6. ### GeoGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

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.

Geo, Nov 1, 2006
7. ### fcvcnetGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

Thanks you very much.

"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.
>

fcvcnet, Nov 2, 2006
8. ### fcvcnetGuest

Thanks you very much.
"Marcus Kwok" <> Ð´ÈëÏûÏ¢ÐÂÎÅ:eiagra\$8dp\$...
> Jim Langston <> wrote:
>> "fcvcnet" <> wrote in message
>> news:ei9ndm\$5lf\$99.com...
>>> 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.

>
> 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
>
> --
> Marcus Kwok
> Replace 'invalid' with 'net' to reply

fcvcnet, Nov 2, 2006
9. ### fcvcnetGuest

Thanks you very much.

"Jim Langston" <> Ð´ÈëÏûÏ¢ÐÂÎÅ:Cz_1h.69\$...
> "fcvcnet" <> wrote in message
> news:ei9ndm\$5lf\$99.com...
>> 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.
>

fcvcnet, Nov 2, 2006
10. ### fcvcnetGuest

fcvcnet, Nov 2, 2006
11. ### ctsGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

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;

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

cts, Nov 2, 2006
12. ### fcvcnetGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

Thanks you very much.

"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;
>
> fcvcnet wrote:
>> Hi,
>> I got result 1.#QNAN00000000 and -1.#IND000000000 in my programme,
>> what
>> happened?
>> why?
>> Thanks.

>

fcvcnet, Nov 3, 2006
13. ### fcvcnetGuest

Re: faq 1.#QNAN00000000 and -1.#IND000000000

#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?

fcvcnet, Nov 3, 2006