Dual C ++ precision loss

I am developing a C ++ application that runs on a linux environment. I need to store a lot of value with 6 decam places. I used a double for this. But after assignment, the double variable does not contain the exact value. It is rounded.

Example:

double dValue = 79447461534242.913072; //Assignement of value

But after that, when I see the value in dValue, it is something like 79447461534242.906

Can someone let me know why this is happening and offer me the correct data type that can contain the exact value without losing accuracy.

+5
source share
4 answers

In a typical implementation, a doublehas about 15 digits of the exact total. It doesn't matter before or after the decimal point, it's only 15 digits.

20 , .

+5

++ IEEE, . , , , GNU MP Bignum .

+5

53 . 16 .

, long double , , , double.

If you need more precision than you can get from your own machine types, you will need a high-precision digital library such as GMP .

+2
source

On linux, you can use __float128, which is an even floating point type.

+1
source

All Articles