Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What good is modulus (%)?

Name: Anonymous 2010-06-27 14:52

I've written dozens of computer programs, and have never even come close to having to use this silly operator.

Name: Anonymous 2010-06-27 14:59

It's used in cryptography all the fucking time.
Die in a fire you fucking PHP dipshit.

Name: Anonymous 2010-06-27 15:05

lol

Name: Anonymous 2010-06-27 15:21

In most languages % isn't a true modulus operator; it's just a remainder operator.

Name: Anonymous 2010-06-27 17:02

i'll believe it when i see an actual code sample that can't be reproduced without the use of (%)

Name: Anonymous 2010-06-27 17:05

>>2
I use modulus in PHP. Problem?

Name: Anonymous 2010-06-27 17:06

>>5
Seeing as i % j is semantically identical to i - (i / j) * j, you may never believe.

Name: Anonymous 2010-06-27 17:15

>>7
That breaks on negative numbers.
A lot of languages do behave like that, but that's not a true modulus operation.

Name: Anonymous 2010-06-27 17:15

Silly OP.

Name: Anonymous 2010-06-27 17:24

>>8
True, but you know what they say - J'ai découvert une vache.

Name: Anonymous 2010-06-27 17:28

Pure residue arithmetic.

Name: Anonymous 2010-06-27 17:34

>>10
Rétournez au /b/, s'il vous plaît.

Name: Anonymous 2010-06-27 17:40

You would use the modulus in favor of it's mathematical counterparts you can conjure up because of simplicity. Wouldn't you prefer one "%" instead of "i-(i/j)*j" simply for simplicity? Clearly, it clears up your code.

Name: Anonymous 2010-06-27 18:15

I work with Mr. Modulus daily to solutionize Chinese reindeer theorem.

Name: Anonymous 2010-06-27 18:16

>>13
The same argument can be made for any function imaginable. If the function sees next to no use, it's just cluttering up the syntax.
That said, >>1 is trollan and % is clearly very useful, even if it's broken as a modulo operator.

Name: Anonymous 2010-06-27 18:26

This may go without saying, but the reason % behaves like a remainder operator instead of a proper modulo operator most of the time is because x86 gives you the remainder for free when you do division.
Does the C standard actually specify the behavior of %, or are there platforms where it does behave properly?

Name: Anonymous 2010-06-27 18:32

>>14
Solutionize my anus, please?

Name: Anonymous 2010-06-27 18:33

>>16
So tell me, what is the difference between a remainder and a modulus??

Name: Anonymous 2010-06-27 18:41

>>18
How it behaves with negative numbers. When both divisor and dividend are positive, they behave identically.
When the dividend is negative and the divisor is positive, the remainder will usually be negative (though the problem is really ill-defined), but the result of the modulo operation will always be positive.
When the divisor is negative, the modulo operator either is undefined or has a negative result, depending on how strict you want to be. The sign of the remainder will generally depend on the sign of the dividend (though again, it's ill-defined).

Name: Anonymous 2010-06-27 19:09

read SICP, it comes up in SICP.

Name: Anonymous 2010-06-27 19:12

>>20
> (% 5 3)
reference to undefined identifier: %


'-._                  ___.....___
    `.__           ,-'        .-'  \
        `''-------'          / o )  `._
                              `-'      (
                                        \
                                         \
                                   ______)
   ................._          .-''    /
                     `-.._         _.-'
                          `'-----''

Name: Anonymous 2010-06-27 20:15

>>21
try mod

Name: Anonymous 2010-06-27 20:18

>>22
> (mod 5 3)
reference to undefined identifier: mod

Name: Anonymous 2010-06-27 20:33

>>23
try modulus

Name: Anonymous 2010-06-27 20:38

>>23
>>21

It's modulo

Name: Anonymous 2010-06-27 20:40

>>25
It is. And not only that, it's a real modulo operation!

> (modulo -5 3)
1

Name: Anonymous 2010-06-27 22:34

>>26
Un provocateur apparaît!
>>> -5 % 3
1

Name: Anonymous 2010-06-27 23:01

>>27
Yeah, most scripting languages get it right. Python, Ruby, and Perl all get 1, PHP (obviously) gets -2.

For other languages, Haskell gets 1, C and Java both get -2. Though in Java's ``defense'', they explicitly call % the remainder operator in the docs.

Name: Anonymous 2010-06-27 23:09

>>21
Oh god I lol'd so hard at the sad progsnake.

Name: Anonymous 2010-06-27 23:09

Haskell has both rem and mod, like a BOSS

Name: Anonymous 2010-06-28 0:02

-5 3 mod . 1  ok

Name: Anonymous 2010-06-28 2:59

>>29
That's sad.  You are sad.  >>21 is sad.

Name: Anonymous 2010-12-09 3:22

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List