Remainder(n, d) Better than MOD, same as capping wrapping? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8) +---- Thread: Remainder(n, d) Better than MOD, same as capping wrapping? (/showthread.php?tid=1227) Pages:
1
2
|
Remainder(n, d) Better than MOD, same as capping wrapping? - bplus - 12-03-2022 Break this? For ideal modulus, I imagine it should be between 0 and the divisor = modulus whether divisor is pos or negative. I read johannhowitzer Wrapping, capping and other... and it all fell in place what we are trying to reach, keeping numbers between 0 and the divisor whether integer or float like Pi, we just want a proper remainder. Code: (Select All) _Title "Remainder test" ' b+ for a modulus that always returns a number between 0 and divisor BTW best toggle I've seen and used often from Chia Pet: toggle = 1 - toggle RE: Remainder(n, d) Better than MOD, same as capping wrapping? - Pete - 12-03-2022 @bplus I responded to the formula Chris posted, in that thread, with a modification for negative mods... Code: (Select All) _Title "Remainder test" ' b+ for a modulus that always returns a number between 0 and divisor So by putting ABS() in those two places your posted code will now handle negative modulo entries, like 7,-5 and -7,-5. Pete RE: Remainder(n, d) Better than MOD, same as capping wrapping? - Jack - 12-03-2022 Pete, bplus is correct, there's no need for Abs I posted basically the same in post #29 https://staging.qb64phoenix.com/showthread.php?tid=1195&pid=10773#pid10773 RE: Remainder(n, d) Better than MOD, same as capping wrapping? - bplus - 12-03-2022 Correct Jack, thanks. My criteria for the return value is for it to be between 0 and the denominator, as stated right with the code. This is a common requirement and not some wild idea I just came up with. -5 into -7 leaves -2 remainder. Mainly the first post Remainder## keeps the numbers returned between 0 and the denominator. RE: Remainder(n, d) Better than MOD, same as capping wrapping? - Pete - 12-04-2022 Guys, I was going off of this: https://www.calculators.org/math/modulo.php Amazing how much disagreement exists in so many of these math sites... Pete RE: Remainder(n, d) Better than MOD, same as capping wrapping? - bplus - 12-04-2022 Yes, it could go either way I suppose. I see real use from me with keeping the return between 0 and denominator. RE: Remainder(n, d) Better than MOD, same as capping wrapping? - Pete - 12-04-2022 (12-04-2022, 01:38 AM)bplus Wrote: Yes, it could go either way I suppose. I see real use from me with keeping the return between 0 and denominator. I've read it depends on the language how the results are represented. So without any reliable consistency, and a few different definitions, I'm in your boat. Use what is beneficial. To me a number MOD 5 should make a nice 1,2,3,4,5 pattern for file record recognition. In the second loop that is accomplished by setting the patented pattern variable to 1. Code: (Select All) $CONSOLE:ONLY Pete RE: Remainder(n, d) Better than MOD, same as capping wrapping? - mnrvovrfc - 12-31-2022 Barely remember that MOD operator thread that went a ridiculous number of posts, and something about it. This is something I have used many times programming in BASIC and in Lua. Where [n] is the dividend and when the answer requires [1,n] and not [0,n-1]. Code: (Select All) FUNCTION modslide~&& (divi AS _UNSIGNED _INTEGER64, dsor AS _UNSIGNED _INTEGER64) RE: Remainder(n, d) Better than MOD, same as capping wrapping? - SMcNeill - 12-31-2022 Why not just make 2 distinct mods which you can then call upon to get the output in whatever format you want? Code: (Select All) Print ModP(10, 3), 10 Mod 3, ModN(10, 3) RE: Remainder(n, d) Better than MOD, same as capping wrapping? - PhilOfPerth - 12-31-2022 (12-03-2022, 05:22 PM)bplus Wrote: Break this?I didn't see Chia Pet's post, but toggle = 1 - toggle always gives result=toggle; to toggle between 1 and 0 shouldn't it be toggle = Abs(toggle - 1) ? |