max()
原文
max()はマクロ関数です。2つの数値の最大値を計算します。
書式
max(x,y)
引数
x :最初の数字。 任意の数値または数値式である可能性があります。
y :第2の数字。 任意の数値または数値式である可能性があります。
戻り値
2つの数字の大きい方を返します。
利用例
code:sample.ino
sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20
// (effectively ensuring that it is at least 20)
補足: max()は変数の範囲の下限を制約するためによく使用され、min()は範囲の上限を制限するために使用されます。
注意
max()を利用する場合、カッコ内で他の関数の使用は避けてください。 結果が正しくない可能性があります。
マクロ関数のため引数の評価の順番が、通常の関数と異なる場合があります。
code:sample.ino
max(a--, 0); // avoid this - yields incorrect results
a--; // use this instead -
max(a, 0); // keep other operations outside max()
Arduinoとの互換性
max()のMaple(Arduino STM32)バージョンはArduinoと互換性があります。
関連項目]
min()
constrain()
License and Attribution: Portions of this page were adapted from the Arduino Reference Documentation, which is released under a Creative Commons Attribution-ShareAlike 3.0 License.
このドキュメントはleafLabs, LLC.が執筆し、たま吉が翻訳・一部加筆修正したものです。
Arduino STM32 リファレンス 日本語版 に戻る