floating point numbers precision

Hello

I'm solving some problem with doubles
The numbers which I'm using are of order 10^7
I'm getting accuracy errors up to 0.1, how to avoid that
My code contains too many function that cause errors like (sqrtl function, acos function, square calculations etc..)
Is there any way to get ride of precision error or this is an inevitable error when I work with double ?

note : I get the error of 0.1 although I'm using the long double
There's no way to answer this question without seeing code. Precision errors can come from all sorts of places. Some are avoidable, some aren't.
@helios
I wanted to share it but it's about 240 lines and has many functions so it's difficult to be shared and understood :(
But if my question cannot be answered, can you please give some advice to work with doubles ?
Is it normal to get error up to 0.1 ?
Thx
integers have up to 10^18 in 64 bit.
if you simply define a shift of say 1000 or 10000 or whatever (like working in millimeters instead of meters, etc) you will keep pure precision without as much aggravation.
you have to do what you have to do with the trig and such, but you can move it back into the best result you can store using the ints for each one

there is no such thing as a standard long double, its not standard and could be anything from a standard double to 80 or 100+ bits.

its worth your time to read a paper or two on doubles. its not 0.1 so much as significant digits. expected 10^-10 accuracy on values around 10^10 is not gonna happen, the range isnt enough for it.
there are many techniques for dealing with it, eg in linear algebra you normalize your matrix or vector (divide all by largest entry and factor it out). It depends on the problem at hand what you can do to it. you can make a fraction class, though that fails on irrationals somewhat.
Last edited on
240 lines is pretty small. Just post the code.
Topic archived. No new replies allowed.