Math.abs()不能办到的事
2012-06-10 22:50
99 查看
Math.abs( T a) 是对数据进行求绝对值的,但是在下面的测试上就不能够完美的表现出他的功能。对于Integer.MIN_VALUE和Long.MIN_VALUE来说,Math.abs()对他们不起作用。返回的还是原来的值。
public class absTest {public static void main(String[] args) {int min = Integer.MIN_VALUE;System.out.println(min); // 输出-2147483648min = Math.abs(min);System.out.println(min); // 输出-2147483648// 说明Math.abs(int MIN_VALUE) 不能将其转化为正整数,同理对于Long型也是一样的// 在Math.abs()的文档中有特别的说明说是对于Long.MIN_VALUE、Integer.MIN_VALUE 的值(即能够表示的最小负 int、long 值),// 那么结果与该值相同且为负。//下面输出的结果为 min_valueif(min == Integer.MAX_VALUE)System.out.println("max_value");else if(min == Integer.MIN_VALUE)System.out.println("min_value");}}
相关文章推荐
- Math.abs()不能办到的事
- Math.abs()不能办到的事
- Math.abs()不能做到的事情
- Math.abs()不能做到的事情
- math.h的abs返回值()
- JavaScript基础 Math.abs(num) 求num的绝对值
- android6.0 PullToRefreshWebView中的FloatMath.floor()不能用了如何替换
- JavaScript基础 Math.abs(num) 求num的绝对值
- 逆天了我,abs在openjudge不能用(修改版)
- 返回绝对值--Math.Abs 方法
- Math.abs(int) in Java
- 为何Math.abs(Integer.MIN_VALUE) = Integer.MIN_VALUE
- js Math.abs,ceil,floor,round,toFixed函数的使用
- 一种比Math类库abs()方法性能更高的取绝对值的方法
- java函数中math.abs(x)是什么意思
- String.valueOf(Math.abs(new Random().nextInt())
- Math.abs
- Java平方不能用^ .用Math.pow(x, 2)
- 严防Math.abs()返回负数
- Math.abs方法