Negative Mod numbers
-
According to VB.NET
-1 Mod 2 = -1
Is this a WTF moment or has maths changed since I did my degree in it?
-
According to VB.NET
-1 Mod 2 = -1
Is this a WTF moment or has maths changed since I did my degree in it?
It's certainly very incongruous.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
According to VB.NET
-1 Mod 2 = -1
Is this a WTF moment or has maths changed since I did my degree in it?
the behavior of division and modulo is always tricky when dealing with negative numbers; each language can make its own choice, as long as one invariant remains true:
a = b * (a DIV b) + (a MOD b)
for all values of a and b If it doesn't fit your expectation, avoid negative numbers, or write your own little method (or create your own integer type and use operator overloading). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
It's certainly very incongruous.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
is it? would you prefer the integer quotient of -1 and 2 to be -1 and the remainder +1? making sure the remainder has the sign of the dividend makes a lot of sense to me. :) PS: don't ask about negative divisors!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
the behavior of division and modulo is always tricky when dealing with negative numbers; each language can make its own choice, as long as one invariant remains true:
a = b * (a DIV b) + (a MOD b)
for all values of a and b If it doesn't fit your expectation, avoid negative numbers, or write your own little method (or create your own integer type and use operator overloading). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Well, it's easy to work around once one knows, of course... but it took me a while to figure out why I wasn't getting the expected results (out of my function of which this was but one line.) It certainly isn't what I was taught about modulo.
-
is it? would you prefer the integer quotient of -1 and 2 to be -1 and the remainder +1? making sure the remainder has the sign of the dividend makes a lot of sense to me. :) PS: don't ask about negative divisors!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
I was making a pun. A play on words. Modulus operations are part of congruence relations.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
I was making a pun. A play on words. Modulus operations are part of congruence relations.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
you've had me there. but still, I'd rather call it congruous, as I got used to a slightly counter-intuitive but perfectly rational behavior of integer division and modulo (which text books and school classes mostly fail to deal with). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.