I need to get the square root of a 210 digit number accurately, I thought GMP was the right tool for the job, what am I doing wrong?
#include <stdlib.h>
#include <stdio.h>
#include "gmp.h"
int
main (int argc, char *argv[])
{
mpz_t sq_me, sq_out, test;
mpz_init(sq_me);
mpz_init(sq_out);
mpz_init(test);
mpz_set_str (sq_me, argv[1], 10);
mpz_sqrt(sq_out, sq_me);
mpz_mul(test,sq_out,sq_out);
gmp_printf ("%Zd\n\n", sq_out);
gmp_printf ("%Zd\n\n", test);
return 0;
}
Input:
24524664490027821197651766357308801846702678767833275974341445171506160083003858 72169522083993320715491036268271916798640797767232430056005920356312465612184658 17904100131859299619933817012149335034875870551067
Output:
49522383313031109809242226159886283348695660460381271324714928680654813093947239 9634016783775955618921028
24524664490027821197651766357308801846702678767833275974341445171506160083003858 72169522083993320715491034366358025027526868495267716284867043049443779615862887 47102011391915422793532619329760963626718900576784