java.lang
Interface Comparable<T>compareTo
int compareTo(T o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
红色字体的sgn是什么意思啊?
例:Y=Sgn(X):符号函数.
说明: X>0时Y=1;X=0时 Y=0;X<0 时Y=-1.
例: Response.write sgn(5)
输出: 1
Sgn(number)
number 参数可以是任意有效的数值表达式。
返回值
Sgn 函数有如下返回值:
如果 number 为 大于零
Sgn 返回 1
如果 number 为 等于零
Sgn 返回 0
如果 number 为 小于零
Sgn 返回 -1