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/06/22 02:41:02
![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](/uploads/image/z/3999852-36-2.jpg?t=java.lang.Math%E4%B8%AD+min%28double+a%2Cdouble+b%29+%E6%8F%90%E9%97%AEpublic+static+double%E6%88%96%E8%80%85float+min%28double+a%2Cdouble+b%29%7B%2F%2F+this+check+for+NaN%2Cfrom+JLS+15.21.1%2Csaves+a+method+callif+%28a+%3D+a%29return+a%3B%2F%2F+no+need+to+check+if+b+is+NaN%3B+%3C+will+work+correctly%2F%2F+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 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时,
有点费解,你先搜一搜,文章很多.
学语言一定要学会搜索,否则,你的疑问会太多