could it be that my number is so small that it is nan?

Hi.

In my coce, I need to handle small numbers (~e-22) but not always so I can't scale the problem (maybe I'll be able to do so later). During the code, I need to subtract two numbers but sometimes, when I do so, I get a nan answer instead of a number. The subtracted numbers are getting smaller and smaller as the code progress and when I forces larger numbers no nan has appeared. Could it be that the numbers I use are so small that they are nan?


Thanks.


p.s. I know that usually nan is generated by undefined move such as 0/0.
Last edited on
Try compiling this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main(){
    float f = 1;

    while(f != 0){
        f/=2;
        std::cout << f << "  " << 1/f << '\n';
    }

    std::cin.get();
    return 0;
}


Floats start failing at about 2.9e-39.
Doubles should produce a lot better results.
Post some code.
I tried something similar and got the same results. I would love to post some code only I think it's a little bit too big to post. I try to isolate the problem and post it then.

Thanks for now.
Topic archived. No new replies allowed.