-1

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?

cnd
  • 32,616
  • 62
  • 183
  • 313
  • 1
    If your 10^50 is meant to be '10 to the power of 50' then this is not correct, ^ is bitwise OR. – RoneRackal May 30 '12 at 04:31
  • @RaulP.R.O This question points to the concept of a big float more than a big int. Arbitrary-precision decimals are far more appropriate for this question than arbitrary-length integers. – Adam Mihalcin May 30 '12 at 04:32
  • @Sholy You also need to have 1.0 before the pow I think ... but as already answered it won't matter because c floats/doubles will not be precise enough – RoneRackal May 30 '12 at 04:38
  • @RoneRackal nope; dividing an int and a floating-point number results in a floating-point result. –  May 30 '12 at 06:51

2 Answers2

3

You can't make it return false with standard C types. You'll need to use a high-precision floating point library.

Keith Randall
  • 22,985
  • 2
  • 35
  • 54
1

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.