Results are out! Find what you need...fast. Get quick advice or join the chat
Hey there! Sign in to join this conversationNew here? Join for free

Anyone familiar with GNU MP?

Announcements Posted on
Will you get the grades you need for uni? Get prepared today and de-stress, sign up to email alerts for course places! 02-06-2015
Waiting on IB results? Our IB results hub explains everything you need to know 01-06-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

It's IB results day tomorrow

Check out our IB results hub here & get prepared here

Useful resources
x

Think you'll be in clearing or adjustment?

Hear direct from unis that want to talk to you

Get email alerts for university course places that match your subjects and grades. Just let us know what you're studying.

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.