Anyone familiar with GNU MP?

From C++ to PHP, debugging to webhosting; help and discussion about writing your latest program to running your website. NOT for help when your PC won't work.

Announcements Posted on
Please change your TSR password 23-05-2013
Enter our travel-writing competition for the chance to win a Nikon 1 J3 camera 20-05-2013
Sign in to Reply
  1. beepbeeprichie's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Posts: 3,838
    Anyone familiar with GNU MP?
    I'm working on a C++ app which deals with very long floats. I'm using the GNU MP library and it outputs correctly in the console but I really need it to output to a file. Does anyone know how do this (combine ofstream and the MP lib)?

    Thanks!
  2. Psyk's Avatar
    • TSR Royalty
    • Location: Leamington Spa
    • Posts: 19,109
    Re: Anyone familiar with GNU MP?
    (Original post by beepbeeprichie)
    I'm working on a C++ app which deals with very long floats. I'm using the GNU MP library and it outputs correctly in the console but I really need it to output to a file. Does anyone know how do this (combine ofstream and the MP lib)?

    Thanks!
    What's the problem? If you can output it to std out, then what's stopping you outputting to a file instead? What are using to output it to the console?
  3. roblee's Avatar
    • Exalted and Worshipped Member
    • Posts: 1,062
    Re: Anyone familiar with GNU MP?
    I'm not particularly familiar with GMP, but gmp_snprintf() ought to work when used with a temporary buffer. Not elegant, but easy to code and just as fast as anything else (although really, you should just use the fprintf() functions instead of trying to channel everything through ostreams).

    http://gmplib.org/manual/Formatted-O...Functions.html
    Last edited by roblee; 31-03-2012 at 14:21.
  4. maturestudy's Avatar
    • Peer Of The TSR Realm
    • Location: Festive Road
    • Posts: 1,707
    Re: Anyone familiar with GNU MP?
    What's to stop you just writing it to an ofstream?

    Code:
    mpz_t bigint;
    ofstream os(("/tmp/bigintfile");
    ...
    os << "The number I was thinking of was " << bigint << "." << endl;
  5. beepbeeprichie's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Posts: 3,838
    Re: Anyone familiar with GNU MP?
    The manual is ****ing horrendous. I can output fine but the decimal places is wrong when using setprecision().
  6. maturestudy's Avatar
    • Peer Of The TSR Realm
    • Location: Festive Road
    • Posts: 1,707
    Re: Anyone familiar with GNU MP?
    cout << setprecision(28) << fixed << n;
  7. beepbeeprichie's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Posts: 3,838
    Re: Anyone familiar with GNU MP?
    (Original post by maturestudy)
    cout << setprecision(28) << fixed << n;
    I think I've realised my stupid error. Whilst stdprecision (x) sets precision by number of decimal places the GNU MP precisions works by bit precision.
  8. maturestudy's Avatar
    • Peer Of The TSR Realm
    • Location: Festive Road
    • Posts: 1,707
    Re: Anyone familiar with GNU MP?
    (Original post by beepbeeprichie)
    I think I've realised my stupid error. Whilst stdprecision (x) sets precision by number of decimal places the GNU MP precisions works by bit precision.
    I think it's safe to say we'd have been here a long time before I thought of that!
Sign in to Reply
Share this discussion:  
Useful resources
Article updates
Moderators

We have a brilliant team of more than 60 volunteers looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.