Search code examples
cnumbersgmp

C GMP unlimited precision - what i am doing wrong?


i have such code (copy paste from wiki). Its multiplication of those big numbers what u see in code. My gmp version is 5.0.5.

#include <stdio.h>
#include <gmp.h>

int main() {
    mpz_t x;
    mpz_t y;
    mpz_t result;

    mpz_init(x);
    mpz_init(y);
    mpz_init(result);

    mpz_set_str(x, "762323423423423443534512034534534534558254738945", 10);
    mpz_set_str(y, "92635911345345345345234534534534567767i888439081", 10);

    mpz_mul(result, x, y);
    gmp_printf("%Zd\n", result);

    mpz_clear(x);
    mpz_clear(y);
    mpz_clear(result);

    return 0;
}

The result is.. 0. Why?


Solution

  • At first it looked fine, so I had to run it myself and print out your other two variables.

    y is set to 0 because you have a letter "i" in the middle of your number, so it can't parse it.