MOD operator

  • Thread starter Thread starter Michael C#
  • Start date Start date
M

Michael C#

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.
 
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.
 
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.
 
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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top