By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

MOD operator

P: n/a
A statement of the form (m mod n) uses the sign of the first operand (m) as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m) as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #2

P: n/a
Thanks for the reply. I actually have an even worse problem with mod at
this point, and the sign is just one part of it. As far as I can tell, the
Mod function should be the amount by which a number exceeds the largest
integer multiple of the divisor that is not greater than that number. This
definition leads to some inconsistencies I'll have to sort through in order
to figure this out. The problem is that Mod in VB truncates toward zero,
which is throwing these calculations wayyyy off. I need a formula that
truncates toward -infinity.

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m)
as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #3

P: n/a
Thanks for the help. I found a proper Modulo formula that uses the Floor
function to return a correct Modulo, and not just the "Remainder of
Division".

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m)
as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.