作业帮 > 综合 > 作业

java.lang.Math中 min(double a,double b) 提问

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/29 04:49:47
java.lang.Math中 min(double a,double b) 提问
public static double或者float min(double a,double b)
{
// this check for NaN,from JLS 15.21.1,saves a method call
if (a = a)
return a;
// no need to check if b is NaN; < will work correctly
// recall that -0.0 == 0.0,but [+-]0.0 - [+-]0.0 behaves special
if (a == 0 && b == 0)
return -(-a - b);
return (a < b) a :b;
}
1.为什么 if (a = a)后返回a呢?
2.if (a == 0 && b == 0)
return -(-a - b);
NaN = not a number(非法浮点)
NaN =!NaN (它的性质)
你搜“Java NaN”会告诉你非法浮点(NaN)的性质,NAN是无序的,
比较时,总是返回false,
所以,当a为非法浮点时,a!=a 就为真,就返回a作为最小值.
----------------------------------------------------------------------------------
if (a==0 && b==0) 当a或b 接近0.0时,
有点费解,你先搜一搜,文章很多.
学语言一定要学会搜索,否则,你的疑问会太多