The modulus operator seems odd. Does it exist because of integer truncation?

Printable View

- 04-18-2002UnregisteredModulus Operator
The modulus operator seems odd. Does it exist because of integer truncation?

- 04-18-2002Prelude
>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 - 04-18-2002Barjor
And that is excelent to know for alot of mathematical stuff. Like finding prime numbers . finding out deviations etc,,,

- 04-18-2002Unregistered
What I should have asked is, "If we didn't have truncation, would we still have the modulus operator?"

- 04-18-2002Unregistered
If we didn't have truncation, finding the square root of one hundred and twenty would crash a computer.

- 04-18-2002Unregistered
Was the modulus operator developed to recover what is lost after integer truncation?

- 04-18-2002Barjor
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

- 04-18-2002Unregistered
Yes it is a freestanding operator.

-Nic - 04-19-2002Nutshell
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.

- 04-19-2002Shiro
>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