-4

how can I increase accuracy in double.

for example in this code:

#include <stdio.h>


int main() {
    long double a = (long double) 5 / 3;
    printf("%.62LLF", a);
    return 0;
}
Tanhaeirad
  • 169
  • 3
  • 13
  • `double`s are only so precise. – Charles Nov 08 '17 at 16:44
  • 1
    By using an external library. – klutt Nov 08 '17 at 16:45
  • By writing a custom cpp compiler or adding some flags to the existing ones. – Sv Sv Nov 08 '17 at 16:45
  • you really need more accuracy than a long double ? – Stargateur Nov 08 '17 at 16:45
  • 1
    You can't increase accuracy in `double`. Nor any other primitive type for that mater. – Ron Nov 08 '17 at 16:46
  • 2
    Printing decimal digits of a fraction is a problem completely unrelated to `double`, if that's what you want to do I'm sure there is an appropriate duplicate on this site – harold Nov 08 '17 at 16:47
  • Possible duplicate of [Printf big double value with high precision in C](https://stackoverflow.com/questions/35651574/printf-big-double-value-with-high-precision-in-c) – Garf365 Nov 08 '17 at 16:51
  • Perhaps the more interesting question is why do you need better accuracy? – UKMonkey Nov 08 '17 at 17:47
  • Step 1: Use correct print specifier `printf("%.62LLF", a);` --> `printf("%.62LF", a);` (one L and enable all compiler warings). 2) Use exponential notation `"%.62Le"`. 3) Use `a` for complete hex output `printf("%La\n", a);` – chux - Reinstate Monica Nov 08 '17 at 18:59

1 Answers1

2

Floating Point Numbers have a limited precision. Mandatory Reading Here.

The boost.multiprecision library can give you access to higher precision floating point numbers, whether in the form of quad types which simply double the precision of double, or in the form of arbitrary precision rational numbers. If you're willing to take the time to learn how to install and use that library, you'll be able to improve the precision of your numbers.

Xirema
  • 19,889
  • 4
  • 32
  • 68