Search code examples
cfloating-pointnumericaldigits

How to process calculations with a high digit numbers?


When I want to work with big and small digits how must I sum / compare values in C?

#include <stdio.h>
#include <math.h>

int main(void) {
    if (1.0 + (1/pow (10,50)) == 1.0)
        printf("true");
    else
        printf("false");
    return 0;
}

how to make it to return false?


Solution

  • In C99, the most precision you can have is long double, which is either a 64-bit or 128-bit IEEE floating-point number on most modern C compilers/architectures. If you want more precision, consider using some libraries which are, for example, used by GCC:

    GMP (http://gmplib.org/) - arbitrary precision arithmetic for both integers and floats; MPFR (http://www.mpfr.org/) - multiple precision floating-point library (claimed to round correctly) MPC (http://www.multiprecision.org/index.php?prog=mpc) arbitrary-precision complex number library.