(11-29-2022, 12:35 AM)SMcNeill Wrote:(11-29-2022, 12:00 AM)Pete Wrote: Nice! That's a keeper.
I wish I had your math teacher in high school. Well, not really. Mine had big boobs. She probably taught that MOD trick, but I probably missed it because I was too busy concentrating on the power of 2.
Pete
I remember those days of 58008 glory.
When you think about it, the Negative MOD of a number has to be the same as the positive MOD.
After all, how do you get MOD to begin with?? Repetitive subtraction!
27 MOD 5
27 - 5
22 - 5
17 - 5
12 - 5
7 - 5
2 - 5... can't subtract so 2 is the answer.
27 MOD -5
27 + -5
22 + -5
17 + -5
12 + -5
7 + -5
2 + -5.... can't add so 2 is the answer.
Subtract one... add the other... The trick is to always approach zero. As D.J. Keith stressed for us, "that + and - is just *direction* you're traveling in."
In this case, you always want to travel towards 0, to find your answer.
(X MOD Y)= (X MOD -Y)... They're basically the same, as far as I can tell.
I like this explanation, points me towards getting a handle on floats, and thanks for simplifying Pete's ABS & SGN laden thing!
b = b + ...