[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 10 KB, 466x273, 1105.gif [View same] [iqdb] [saucenao] [google]
6756608 No.6756608 [Reply] [Original]

Can someone explain why when I do 4/3 mod 1 I get 1/3, but when I do -4/3 mod 1 I get 2/3? I was looking some work over on google, and got these two results back.

>> No.6756633

"mod 1" means that 1 is equivalent to zero.
4/3 can be written as "1 + 1/3."
1 is equivalent to zero, so 4/3 becomes "0 + 1/3," or just "1/3."
-4/3 can be written as "-1 - 1/3" which becomes "-0 - 1/3" or just "-1/3."
But 1 is equivalent to zero, so "-1/3" is like "0 - 1/3" which is "1 - 1/3" which is "2/3"

>> No.6756817

>>6756608
"mod" is loosely defined and its behavior can vary from one compiler to another.

Compare the division algorithms in this short paper:

http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf

>> No.6757021

>>6756817
It has nothing to do with the behavior of the implementation. Like >>6756633 pointed out, 4/3 = 1/3 (mod 1) which is NOT congruent to 2/3 (mod 1). As long as your calculator is not in error, you will never get 4/3 = 2/3 (mod 1) or -4/3 = 1/3 (mod 1), because that would be wrong.

>> No.6757045
File: 38 KB, 1890x695, mod.png [View same] [iqdb] [saucenao] [google]
6757045