According to the documentation,

mpz_fdiv_q_ui

should round down. However, when 1298 is divided by 62 (20.93), it rounds up to 21. Help anyone?


thanks,
toraora
GMP documentation wrote:
Function: unsigned long int mpz_fdiv_q_ui (mpz_t q, mpz_t n, unsigned long int d)
@ifnottex Set q to n/d, rounded towards -infinity.
I can't say I have any idea why that's happening. What is the code for your use case?
I am converting base 10 number (encode) into a base 62 number.


Code:

 for (int a=counter; a!=0; a--)
    {
          mpf_div_ui (sub_mpf.get_mpf_t(), encodef.get_mpf_t(), int (pow (62, a)));
          sub = floor (mpf_get_ui (sub_mpf.get_mpf_t()));
          mystring = mystring + base62.substr(sub,1);
          mpf_sub_ui (encodef.get_mpf_t(), encodef.get_mpf_t(), sub * pow (62, a));
          cout << "\n" << sub << " " << mystring << " " << base62[sub] << " " << a << " " << encodef;
    }


edit: the cout line is there so i can see what the program is doing
edit2: i have changed mpz to mpf, but same thing happens
Hmm, I see no glaring errors in that code. You of course cout'd the operands to make sure everything is as you expect, right?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement