Code: Select all

`Function cmAMod(ByVal x as Double, ByVal y as Double) as Double`

' Variation of x MOD y for Real Numbers adjusted so that the modulus

' of a multiple of the divisor is the divisor itself rather than zero.

'

' If x MOD y = 0 then result is adjusted to y

Function = x - y * (cmCeiling(x / y) - 1)

End Function

Function cmMod(ByVal x as Double, ByVal y as Double) as Double

' x MOD y for Real Numbers, y<>0

Function = x - y * cmFloor(x / y)

End Function

Function cmCeiling(ByVal x as Double) as Long

' Return smallest interger greater than or equal to x

Function = cmFloor(x * -1) * -1

End Function

Function cmFloor(ByVal x as Double) as Long

' Return largest integer less than or equal to x

Function = Int(x)

End Function