Function Reference


Performs the modulus operation.

Mod ( value1, value2 )


value1 The dividend.
value2 The divisor.

Return Value

Success: the remainder when value1 is divided by value2.
Failure: -1.#IND if the divisor is zero.


This function guarantees that Mod(dividend, divisor) = dividend - Int(dividend / divisor) * divisor.

This function does not guarantee that dividend or divisor can be represented, specifically with floating point numbers.

If integers are passed this function does an integral modulo operation. Otherwise it falls back to a floating point operation which per the previous remark means it may not produce the expected output.




#include <MsgBoxConstants.au3>


Func Example()
        ; Assign a Local variable the number 18.
        Local $iNb = 18

        ; If the mudulus operation of $iNb by 2 equals to 0 then $iNb is even.
        If Mod($iNb, 2) = 0 Then
                MsgBox($MB_SYSTEMMODAL, "", $iNb & " is an even number.")
                MsgBox($MB_SYSTEMMODAL, "", $iNb & " is an odd number.")

        ; Assign a Local variable the modulus operation of 4 by 7.
        Local $iMod1 = Mod(4, 7) ; 4%7 = 4 because the divisor > dividend

        ; Display the result.
        MsgBox($MB_SYSTEMMODAL, "$iMod1", $iMod1)

        ; Assign a Local variable the modulus operation of 1 by 3/4.
        Local $iMod2 = Mod(1, 3 / 4) ; 1%(3/4) = 0.25 because the divisor is a float

        ; Display the result.
        MsgBox($MB_SYSTEMMODAL, "$iMod2", $iMod2)
EndFunc   ;==>Example