Hi, I'm using GNU MP to get very precise square roots of numbers. I have three questions about my code below.
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
int main(int argc, char *argv[])
{
mpf_t num, sqrt;
FILE *out;
mpf_init2(num, 1000000);
mpf_init2(sqrt, 1000000);
printf("Enter a number to get its square root: ");
mpf_inp_str(num, stdin, 10);
printf("\nGetting square root...");
mpf_sqrt(sqrt, num);
printf("Done!");
out = fopen("output.txt", "w+");
if (!out)
{
printf("\nError opening output file!");
getchar();
return 1;
}
printf("\nWriting...");
mpf_out_str(out, 10, 0, sqrt);
printf("Done!");
mpf_clear(num);
mpf_clear(sqrt);
getchar();
return 0;
}
1. It writes the output in scientific notation. It's pointless because its just e1 usually. How would I make it so it's not in scientific notation?
2. It doesn't write all 1000000 digits. I should be getting a file that's about 977kb, but it's only 294. How can I fix that?
3. It allocates on the stack, so if I try to do 1 billion digits, I get a stack overflow. How can I make it allocate on the heap?
Hope that's not too much :P. Thanks in advance.
I'm on Windows XP using MinGW.