Search the web
Sign In
New User? Sign Up
wcalc · Wcalc Users
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
mod doesn't work wery well   Message List  
Reply | Forward Message #57 of 114 |
Re: [wcalc] mod doesn't work wery well

Kyle Wheeler <kyle-wcalc-yahoo@...> schrieb:

>> mpfr_div(output, first, second, GMP_RNDN);
>> if (MPFR_SIGN(first) >= 0)
>> mpfr_floor(output, output);
>> else
>> mpfr_ceil(output, output);
>> mpfr_mul(output, output, second, GMP_RNDN);
>> mpfr_sub(output, first, output, GMP_RNDN);
>
> Hmm, how is that different from mpfr_rint(output, output, GMP_RNDZ); ?

Well, rounding output towards zero would pick floor() or ceil()
depending on the sign of output. I'm checking the sign of the first
operand instead. So, if first and output have the same sign (i.e. if
second is positive) both algorithms are equal. If first and output have
opposite signs (i.e. second is negative) I'm doing the opposite (i.e.
rounding away from zero).

Cheers,
Ingo





Fri Jun 30, 2006 8:35 am

ingo_swt
Offline Offline
Send Email Send Email

Forward
Message #57 of 114 |
Expand Messages Author Sort by Date

I wanted the remainder of a division with big numbers, this is what I've done: $ time wcalc "2^56 - floor(2^56 / 57)*57" = 4 real 0m0.004s user 0m0.001s ...
Daniele
scrows@...
Send Email
Jun 28, 2006
10:15 am

... Heh, right. Counting up to 2^56 in 57-steps might take a while. ;-) ... Sure. Patch attached. Cheers, Ingo...
Ingo van Lil
ingo_swt
Offline Send Email
Jun 28, 2006
6:30 pm

... Hmm. What is currently in CVS is this: mpfr_set_ui(temp, 0, GMP_RNDN); mpfr_div(temp, first, second, GMP_RNDN); mpfr_rint(temp, temp, GMP_RNDZ); ...
Kyle Wheeler
m3m0ryh0l3
Offline Send Email
Jun 29, 2006
4:18 am

... What's the first line good for? ... -20 is not an option. The question is: When performing the integer division of -340 and 60, do you round the result by...
Ingo van Lil
ingo_swt
Offline Send Email
Jun 29, 2006
8:03 am

... Hmm, not much, come to think of it. ... Hmm, well, I tend to like not being restrictive, and I also like maintaining the existing behavior. In Wcalc 1.x,...
Kyle Wheeler
m3m0ryh0l3
Offline Send Email
Jun 29, 2006
9:35 pm

... Actually, if I'm reading the ADA reference manual correctly, the REM operator does exactly what your algorithm does (A REM B keeps the sign of A) while the...
Ingo van Lil
ingo_swt
Offline Send Email
Jun 29, 2006
11:05 pm

... Well, I'm not saying I'm in love with ADA, I'm just suggesting we preserve the existing behavior for % and do a better/different one with a new operator...
Kyle Wheeler
m3m0ryh0l3
Offline Send Email
Jun 30, 2006
1:23 am

... Well, rounding output towards zero would pick floor() or ceil() depending on the sign of output. I'm checking the sign of the first operand instead. So, if...
Ingo van Lil
ingo_swt
Offline Send Email
Jun 30, 2006
8:35 am

Perhaps I found another bug in the mod operator, I don't know if the result change with the last modifies to the way the mod works, so .. For `m % n' where `m'...
Daniele
scrows@...
Send Email
Jul 5, 2006
3:35 pm

... Nope, that's wrong. Looks like I need to get this fixed version out asap. ~Kyle -- It is easier to be critical than to be correct. -- Benjamin Disraeli...
Kyle Wheeler
m3m0ryh0l3
Offline Send Email
Jul 6, 2006
7:01 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help