Phil Lucht Math & Physics Archive
Home / Math and Physics Files / Math / Math Binder

remainder and mod stuff

DOCX · 17.0 KB
Open DOCX file

A brief note by Phil (dated 11.22.04) written to clear up his own confusion about the remainder function. It defines Int(x/y), Frac(x/y) and Rem(x,y) with numerical examples and Excel equivalents, and proves that Rem(x,y) = Frac(x/y)*y. It also notes that Rem matches the modulo function and that C's % operator works only on integers, so fmod is needed for general reals.

AI-written summary; may contain errors.

Extracted text (machine-read; may contain errors)
The Remainder Function PhL 11.22.04 As usual, I get confused by the most trivial of things, so here goes. 1. Integer Part. Suppose we have two positive real numbers x and y. Then define Int(x/y) the integer part of the result of dividing x by y. = int(x/y) in Excel = floor(x/y,1). Example: Int(5.3/2.1) = Int(2.5238) = 2. 2. Fractional Part. Suppose we have two positive real numbers x and y. Then define Frac(x/y) the fractional part of the result of dividing x by y = (x/y) - int(x/y) in Excel Example: Frac(5.3/2.1) = Frac(2.5238) = .5238 Theorem #1: (x/y) = Int(x/y) + Frac(x/y) Proof: obvious except at boundaries 3. Remainder (Mod). Suppose we have two positive real numbers x and y. Then define: Rem(x,y) x - Int(x/y)*y = mod(x,y) in Excel This is meant to be what is left over (the remainder) after you keep subtracting y from x until the result is in the range (0,y). Example: Rem(5.3, 2.1) = 5.3 - Int(5.3/2.1)*2.1 = 5.3 - 2*2.1 = 5.3 - 4.2 = 1.1 Theorem #2: Rem(x,y) = Frac(x/y)*y Proof: Rem(x,y) x - Int(x/y)*y = [ (x/y) - Int(x/y) ]*y = Frac(x/y)*y by Theorem 1. This Rem(x,y) is the same as the Modulo function mod(x,y). Results so far are compatible with http://www.voidware.com/modsecret.htm. Fact: In the C language there is an operator % and you can talk about x % y. However, it is only defined for x,y being integers. If you want the general thing, you have to use fmod(x,y).