The modulus operator seems odd. Does it exist because of integer truncation?
The modulus operator seems odd. Does it exist because of integer truncation?
>The modulus operator seems odd.
How so? After a division of two numbers there is a remainder, the modulus operator gives you that value.
-Prelude
My best code is written with the delete key.
And that is excelent to know for alot of mathematical stuff. Like finding prime numbers . finding out deviations etc,,,
What I should have asked is, "If we didn't have truncation, would we still have the modulus operator?"
If we didn't have truncation, finding the square root of one hundred and twenty would crash a computer.
Was the modulus operator developed to recover what is lost after integer truncation?
Not as far as i know. It is a free standing full fledge operator just as +-*/. I don't see any connection between the truncation and modolus
Yes it is a freestanding operator.
-Nic
How do u calculate a mod of something in terms of computer? Like how does the comp calculates it? Human can calculate a remainder of a number by doing working outs on a piece of paper i know.
>Human can calculate a remainder of a number by doing working
>outs on a piece of paper i know.
You can translate that algorithm to C.
9 / 4 = 2
4 * 2 = 8
9 - 8 = 1
so
9 % 4 = 9 - (9 / 4 * 4) = 1