abs(x)
描述
計算出一個數值的絕對值。
參數
x: 欲計算的數值
回傳
x: 若 x 大於或等於零
-x: 若 x 小於零
警告
由於 abs() 函式實作方法 (使用巨集) 的關係,在括號 () 中避免使用其他函式或運算,否則可能產生不正確的結果。
abs(a++); // 避免此作法: 可能會產生錯誤結果 a++; // 改用此做法: abs(a); // 將運算式移至括號()外
本頁由熱血青年 LBU 譯自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
