Mod
执行模数运算.
Mod ( value1, value2 )
参数
返回值
成功:
|
返回值 1 除以值 2 后的余数.
|
失败:
|
返回 -1.#IND, 除数为零.
|
备注
函数确保 Mod(被除数, 除数) = 被除数 - Int(被除数 / 除数) * 除数.
函数不能确保被除数或除数可以精确表示, 特别是浮点数.
如果传递整数, 函数作完整的模操作; 否则执行浮点运算, 则可能不会产生预期的输出.
函数示例
#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)
; 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)
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令 exect 调用
参见:
Int
Mod(1,3/4) ;; 返回0.25,因为浮点除数
exect=$var_n1=Mod(4,7)||$var_n2=Mod(1,3/4)||$var_n3=Mod(4,2) GLOBALEXECT<a> ;; 计算除数的剩余部分
<FOR> 1 <TO> 5 exect=$var_sc=Mod(:INDEX:)=0?'blue-red':'red-blue'||_ViewValues('$var_sc') <NEXT> ;; 在循环中获取变量$var_sc与奇数/偶数计数器的不同值的示例
exect=$var_aa=StringSplit('AA|BB|CC|DD|EE|','|',1) <FOR> 1 <TO> 10 exect=$var_sc=Mod(:INDEX:,5)||$var_sc=$var_sc=0?5:$var_sc||$var_sc=GLOBALEXECT<$var_sc>||_ViewValues('$var_sc') <NEXT> ;; 在一个循环中替代使用数组值和$var_aa的示例
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|