Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 768547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:11:56+00:00 2026-05-14T18:11:56+00:00

I’m attempting to store the value 0.9999 into an mpfr_t variable using the mpfr_set_str()

  • 0

I’m attempting to store the value 0.9999 into an mpfr_t variable using the mpfr_set_str() function

But 0.9999 is rounded to 1 (or some other value != 0.9999) during storage, no matter the round value (GMP_RNDD, GMP_RNDU, GMP_RNDN, GMP_RNDZ)

So what’s the best method to store 0.9999 in an mpfr_t variable using mpfr_set_str()?
Is it possible?

Here is my test program, it prints “buffer is: 1”, instead of the wanted “buffer is: 0.9999”:

int main()
{

    size_t precision = 4;
    mpfr_t mpfrValue;

    mpfr_init2(mpfrValue, precision);
    mpfr_set_str(mpfrValue, "0.9999", 10, GMP_RNDN);

    char *buffer = (char*)malloc((sizeof(char) * precision) + 3);
    mp_exp_t exponent;

    mpfr_get_str(buffer,
                 &exponent,
                 10,
                 precision,
                 mpfrValue,
                 GMP_RNDN);

    printf("buffer is: %s\n", buffer);

    free(buffer);
    mpfr_clear(mpfrValue);

    return 0;
}

Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:11:57+00:00Added an answer on May 14, 2026 at 6:11 pm

    precision is given in bits, not in decimal digits, as you seem to be assuming. It seems that you can reprint the correct value to 4 decimal digits with 15 bits precision. Also, you can output directly using mpfr_printf.

    If you do need to use mpfr_get_str, I would pass null as the first parameter. If you do that the string is allocated for you. Then, to free it you call mpfr_free_str.

    int main()
    {
        size_t precision = 15;
        mpfr_t mpfrValue;
    
        mpfr_init2(mpfrValue, precision);
        mpfr_set_str(mpfrValue, "0.9999", 10, GMP_RNDN);
    
        mpfr_printf("Value is: %Rf\n", mpfrValue);
        mpfr_clear(mpfrValue);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.