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论坛