Re: FORMULA THAT CALCULATES HH:MM ON THIRD SHIFT(BETWEEN TWO DAYS)



I get that Int rounds down for negative numbers, and I understand why
-0.625 - 1 * INT(-0.625/1) = .375

So if Mod is defined as <<MOD(n, d) = n - d*INT(n/d)>>, I get it. (And
it's damn handy for figuring the difference between two times spanning
midnight.)

But if Mod is defined as "Returns the remainder after number is
divided by divisor. The result has the same sign as divisor", then I
don't get it.

If 11 is divided by 3, the remainder is 2.

What is the remainder of -11 divided by 3 ?
What is the remainder of 11 divided by -3 ?

-11/3 = 11/-3 = -(11/3) !!!

Ok, I can see when I do the long division with either the divisor or
the dividend being negative I am either subtracting 9 from -11 (=-20)
or subtracting -9 from 11 (=20), which is different from the remainder
when both divisor and dividend are positive, 2 (or both negative, -2).

I guess I never knew what the "remainder" was when the divisor and
dividend were different signs. It somehow ends up being what the
remainder would have been if all was positive, added to the divisor,
the divisor keeping its sign, and the remainder keeping the sign of
the dividend. Let's see... Oh, that would be n - d*INT(n/d).

Ok, I'm done ;)



.



Relevant Pages

  • Re: Sign conventions for remainder
    ... What about if both the divisor and the dividend are negative? ... > If the divisor is positive, the remainder should still be in the range ... options in your package for the several possible sensible behaviours. ...
    (sci.math)
  • [SUMMARY] Long Division (#180)
    ... is done repeatedly dividing the divisor into each digit of the ... dividend combined with the remainder of the previous division step. ... And so our quotient is 0372, usually written without leading zeros as ...
    (comp.lang.ruby)
  • Re: Sign conventions for remainder
    ... Addition, subtraction, and multiplication ... What about if both the divisor and the dividend are negative? ... The remainder is a piece of the dividend; ...
    (sci.math)
  • Re: relationship between divisor and dividend in CRC codes
    ... between divisor and dividend in CRC codes ... Dividend and divisor are ... The remainder is the polynomial, ...
    (sci.crypt)
  • Re: Dividing 512 bit number by 128 bit number in C program
    ... calculating the quotient and the remainder before returning. ... In one of the inner loops, the divisor is positioned so that its most ... A bit-wise subtraction of divisor from dividend is performed ... bool borrow = false; ...
    (sci.crypt)

Loading