Min()

從 YFRobotwiki
跳到: 導覽搜尋

描述

計算兩個數字的最小值。


參數

  • x: 第一個數字,任何數據類型
  • y: 第二個數字,任何數據類型


返回

兩個數字中的較小的數字。


示例

sensVal = min(sensVal, 100); // assigns sensVal to the smaller of sensVal or 100
                             // ensuring that it never gets above 100.


注意

可能與直覺相反,max()通常用於約束變量範圍的下限,而min()用於限制範圍的上限。


警告

由於執行min()函數的方法,避免在括號內使用其他函數,否則可能會導致不正確的結果

min(a++, 100);   // avoid this - yields incorrect results

min(a, 100);
a++;            // use this instead - keep other math outside the function


擴展閱讀

- max()
- constrain()




返回Arduino語法參考列表

更多建議和問題歡迎反饋至 YFRobot論壇