Function Reference


Mod

Performs the modulus operation.

Mod ( value1, value2 )

Parameters

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.

Remarks

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.

Related

Int

Example

#include <MsgBoxConstants.au3>

Example()

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.")
        Else
                MsgBox($MB_SYSTEMMODAL, "", $iNb & " is an odd number.")
        EndIf

        ; 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