Hey there Sign in to join this conversationNew here? Join for free

Anyone familiar with GNU MP?

Announcements Posted on
TSR Movie Madness is down to only 8 films! Help decide on the final 4 now! 15-07-2014
    • Thread Starter
    • 6 followers
    Offline

    ReputationRep:
    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!
    • 13 followers
    Offline

    ReputationRep:
    (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?
    • 4 followers
    Offline

    ReputationRep:
    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
    • 0 followers
    Offline

    ReputationRep:
    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;
    • Thread Starter
    • 6 followers
    Offline

    ReputationRep:
    The manual is ****ing horrendous. I can output fine but the decimal places is wrong when using setprecision().
    • 0 followers
    Offline

    ReputationRep:
    cout << setprecision(28) << fixed << n;
    • Thread Starter
    • 6 followers
    Offline

    ReputationRep:
    (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.
    • 0 followers
    Offline

    ReputationRep:
    (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!

Reply

Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?

    this is what you'll be called on TSR

  2. this can't be left blank
    this email is already registered. Forgotten your password?

    never shared and never spammed

  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. By joining you agree to our Ts and Cs, privacy policy and site rules

  2. Slide the button to the right to create your account

    Slide to join now Processing…

Updated: March 31, 2012
New on TSR

Student crowdfunds degree

Graduate raises £26,000 online for Masters course

Article updates
Useful resources
Reputation gems:
You get these gems as you gain rep from other members for making good contributions and giving helpful advice.