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
It would help if you specified what differences you are addressing. Which things are different in FB and how do they behave in PB?
I certainly hope PB never had x mod y return y when x mod y is supposed to be 0! Because that is not a modulus by definition. If PB ever did that I would consider that a bug in the compiler.
I presume AMod's general purpose tends to be for finding padding amounts, e.g. tab sizes, where you want to round up to the next multiple, but always with a value of 1 or more.
counting_pine wrote:I presume AMod's general purpose tends to be for finding padding amounts, e.g. tab sizes, where you want to round up to the next multiple, but always with a value of 1 or more.
AMod is useful when a non zero result is wanted. For instance, assume you have an integer contains some number of months and you want to know the ending month. If nMonths = 12 then nMonths MOD 12 is zero but nMonths AMOD 12 is 12.