Results are out! Find what you need...fast. Get quick advice or join the chat
x

Unlock these great extras with your FREE membership

  • One-on-one advice about results day and Clearing
  • Free access to our personal statement wizard
  • Customise TSR to suit how you want to use it

Anyone familiar with GNU MP?

Announcements Posted on
Rate your uni — help us build a league table based on real student views 19-08-2015
  1. 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!
  2. 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?
  3. 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
  4. 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;
  5. Offline

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

    ReputationRep:
    cout << setprecision(28) << fixed << n;
  7. 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.
  8. 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?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  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 to join now Processing…

Updated: March 31, 2012
TSR Support Team

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

New on TSR

Rate your uni

Help build a new league table

Poll
How soon after finishing your degree did you get a job offer
Useful resources
Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.