| | |
GNU MP
![]() |
Hi, I'm using GNU MP to get very precise square roots of numbers. I have three questions about my code below.
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.
C Syntax (Toggle Plain Text)
#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
. 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
--Martin Golding
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
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
![]() |
Similar Threads
- GNU MP Library (or RSA in C++) (C++)
- Gnu Cpp - missing error message on missing return statement (C++)
- Porting from Sun C++ compiler to GNU gcc (C++)
- A problem when I employ GNU Scientific Libraries in a Code (C)
- g++ GNU compiler help (C++)
- GNU GPL Guideline Revision to Launch (Geeks' Lounge)
- problem about the codding (C)
Other Threads in the C Forum
- Previous Thread: Can anyone share concept/program in C to add two 64-bit numbers on a 32-bit machine
- Next Thread: Problem with socket connection
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






