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 callif (a = a)return a;// no need to check if b is NaN; < will work correctly// recall that -0
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 03:45: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 callif (a = a)return a;// no need to check if b is NaN; < will work correctly// recall that -0
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);
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 callif (a = a)return a;// no need to check if b is NaN; < will work correctly// recall that -0
NaN = not a number(非法浮点)
NaN =!NaN (它的性质)
你搜“Java NaN”会告诉你非法浮点(NaN)的性质,NAN是无序的,
比较时,总是返回false,
所以,当a为非法浮点时,a!=a 就为真,就返回a作为最小值.
----------------------------------------------------------------------------------
if (a==0 && b==0) 当a或b 接近0.0时,
有点费解,你先搜一搜,文章很多.
学语言一定要学会搜索,否则,你的疑问会太多