Remainder(n, d) Better than MOD, same as capping wrapping?
#12
(12-31-2022, 03:59 AM)SMcNeill Wrote: Why not just make 2 distinct mods which you can then call upon to get the output in whatever format you want?

Code: (Select All)
Print ModP(10, 3), 10 Mod 3, ModN(10, 3)
Print ModP(10, -3), 10 Mod -3, ModN(10, -3)
Print ModP(-10, 3), 10 Mod 3, ModN(-10, 3)
Print ModP(-10, -3), 10 Mod -3, ModN(-10, -3)
Print ModP(10, 3.14), 10 Mod 3.14, ModN(10, 3.14)
Print ModP(10, -3.14), 10 Mod -3.14, ModN(10, -3.14)
Print ModP(-10, 3.14), -10 Mod 3.14, ModN(-10, 3.14)
Print ModP(-10, -3.14), -10 Mod -3.14, ModN(-10, -3.14)



Function ModP## (num As _Float, div As _Float)
    Dim tempValue As _Float
    If div = 0 Then Error 5: Exit Function
    tempValue = num - Int(num / div) * div
    If tempValue < 0 Then tempValue = tempValue + Abs(div)
    ModP = tempValue
End Function

Function ModN## (num As _Float, div As _Float)
    Dim tempValue As _Float
    If div = 0 Then Error 5: Exit Function
    tempValue = num - Int(num / div) * div
    If tempValue > 0 Then tempValue = tempValue - Abs(div)
    ModN = tempValue
End Function

I don't know if this is reply to me or Minerva. If to me I gotta ask why is 2 functions more than 2 lines long better than 1 function 2 lines long?

I remind all that I started thread with spec that remainder needs to be between 0 and divisor. So why use ABS?
b = b + ...
Reply


Messages In This Thread
RE: Remainder(n, d) Better than MOD, same as capping wrapping? - by bplus - 12-31-2022, 04:33 PM



Users browsing this thread: 4 Guest(s)