Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remainder(n, d) Better than MOD, same as capping wrapping?
#9
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
Reply


Messages In This Thread
RE: Remainder(n, d) Better than MOD, same as capping wrapping? - by SMcNeill - 12-31-2022, 03:59 AM



Users browsing this thread: 1 Guest(s)