Need help from a Good c++ Programmer Urgently!

Pages: 12
Oh and in the <limits> header, you can use numeric_limits<double>::epsilon(), as it's the C++ way. Macros are C.


Good work - I had a vague idea there was a C++ way of doing it.

BTW: even the epsilon isn't really the smalles reprezentable number.


Epsilon is not meant to be the smallest representable number - it is the distance between 1 and the next representable number. This "distance" varies so that is why you need to scale it up.

Epsilon is much bigger than the smallest numbers that doubles can do. Epsilon for a double is about 1e-16, the smallest double is about 1.7e-308. Overriding all this is that doubles really only have 15 significant places of precision .
Actually the smallest double is about 4.94066e-324. Funny how numeric_limits<double>::min() is 2.22507e-308
SVD400,

So you need to use the numeric_limits<double>::epsilon() to help you do your comparison with zero. I would put the result of it into your own variable so you don't have to write all that every time you want to use it.

I would recommend you use doubles rather than floats in your calcs.
Topic archived. No new replies allowed.
Pages: 12