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.