.
. centre de ressources dilemmes et doutes le visage humain de mathématiques Qui sommes-nous Problème de mois activités de promotion babillard
Centrale des maths - centraledesmaths.uregina.ca
Dilemmes & doutes
« D & D »
. .
topic card  

Sujet:

turing

liste de
sujets
. .
nouvelle recherche

Un article trouvé pour ce sujet.
 
Page
1/1
Mod versus Rem in Turing 2013-01-01
Eric pose la question :
I am a teacher teaching computer science using Turing. I am having difficulty understanding why one would use the mod operator versus the rem remainder operator.

Mod seems to make the resulting sign depend on the sign of the divisor, whereas rem makes the resulting sign depend on the dividend.

Examples:

11 mod 5 = 1 and 11 rem 5 =1
-11 mod 5 = 4 and -11 rem 5 = -1
11 mod -5 = -4 and 11 rem -5 =1
-11 mod -5 = -1 and -11 rem -5 = -1

What I can't understand is why this would matter. For example, -11 / 5 = -2.2 and 11 / -5 = -2.2 get the same result.
So how is a remainder dependent on the sign of one of the parts? What benefit would using one over the other have?

Any insight would be most helpful!

Eric

Harley Weston lui répond.
 
Page
1/1

 

 


Centrale des maths reçoit une aide financière de l’Université de Regina et de The Pacific Institute for the Mathematical Sciences.

CMS
.

 

accueil centre de ressources accueil Société mathématique du Canada l'Université de Regina PIMS