GNU MP

Reply

Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

GNU MP

 
0
  #1
Apr 29th, 2009
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.
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,602
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: GNU MP

 
0
  #2
Apr 30th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC