944,008 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 434
  • C RSS
Apr 29th, 2009
0

GNU MP

Expand Post »
Hi, I'm using GNU MP to get very precise square roots of numbers. I have three questions about my code below.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <gmp.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. mpf_t num, sqrt;
  8. FILE *out;
  9.  
  10. mpf_init2(num, 1000000);
  11. mpf_init2(sqrt, 1000000);
  12.  
  13. printf("Enter a number to get its square root: ");
  14. mpf_inp_str(num, stdin, 10);
  15.  
  16. printf("\nGetting square root...");
  17. mpf_sqrt(sqrt, num);
  18. printf("Done!");
  19.  
  20. out = fopen("output.txt", "w+");
  21.  
  22. if (!out)
  23. {
  24. printf("\nError opening output file!");
  25. getchar();
  26. return 1;
  27. }
  28.  
  29. printf("\nWriting...");
  30. mpf_out_str(out, 10, 0, sqrt);
  31. printf("Done!");
  32.  
  33. mpf_clear(num);
  34. mpf_clear(sqrt);
  35. getchar();
  36. return 0;
  37. }

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 . Thanks in advance.
I'm on Windows XP using MinGW.
Last edited by TheBeast32; Apr 29th, 2009 at 8:19 pm.
Similar Threads
Reputation Points: 79
Solved Threads: 6
Posting Whiz in Training
TheBeast32 is offline Offline
236 posts
since Dec 2007
Apr 30th, 2009
0

Re: GNU MP

i used this library several years ago for a project... it's quite impressive.... however, i don't really remember anything to help you with.

so, i don't want to sound dismissive, but i think this sort of highly specialized library you'll probably find more precise help on their mailing list or archives

http://gmplib.org/#MAILINGLISTS
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Owerwriting problem (reading file)
Next Thread in C Forum Timeline: Problem with socket connection





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC