先上实例:
System.out.println(Math.pow(1d, 0) + " If the second argument is positive or negative zero, then the result is 1.0."); System.out.println(Math.pow(1d, -0) + " If the second argument is positive or negative zero, then the result is 1.0."); System.out.println(Math.pow(2d, 1.0d) + " If the second argument is 1.0, then the result is the same as the first argument."); System.out.println(Math.pow(2d, Double.NaN) + " If the second argument is NaN, then the result is NaN."); System.out.println(Math.pow(Double.NaN, 1) + " If the first argument is NaN and the second argument is nonzero, then the result is NaN."); System.out.println(Math.pow(2d, Double.POSITIVE_INFINITY) + " If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity."); System.out.println(Math.pow(-0.5d, Double.NEGATIVE_INFINITY) + " If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity."); System.out.println(Math.pow(2d, Double.NEGATIVE_INFINITY) + " If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero."); System.out.println(Math.pow(0.5d, Double.POSITIVE_INFINITY) + " If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero."); System.out.println(Math.pow(1d, Double.POSITIVE_INFINITY) + " If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN."); System.out.println(Math.pow(0, 1d) + " If the first argument is positive zero and the second argument is greater than zero, or the first argument is positive infinity and the second argument is less than zero,then the result is positive zero. "); System.out.println(Math.pow(Double.POSITIVE_INFINITY, -1d) + " If the first argument is positive zero and the second argument is greater than zero, or the first argument is positive infinity and the second argument is less than zero,then the result is positive zero. "); System.out.println(Math.pow(0, -1d) + " If the first argument is positive zero and the second argument is less than zero, or the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity."); System.out.println(Math.pow(Double.POSITIVE_INFINITY, 1d) + " If the first argument is positive zero and the second argument is less than zero, or the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity."); System.out.println(Math.pow(-0, Double.POSITIVE_INFINITY) + "111 If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero."); System.out.println(Math.pow(-0d, 3) + " If the first argument is negative zero and the second argument is a positive finite odd integer, or the first argument is negative infinity and the second argument is a negative finite odd integer,then the result is negative zero."); System.out.println(Math.pow(-0, 3) + " The result will get 0.0 if we use int 0 or long 0, expect is -0.0"); System.out.println(Math.pow(Double.NEGATIVE_INFINITY, -3d) + " If the first argument is negative zero and the second argument is a positive finite odd integer, or the first argument is negative infinity and the second argument is a negative finite odd integer,then the result is negative zero."); System.out.println(Math.pow(-0, Double.NEGATIVE_INFINITY) + "222 If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity."); System.out.println(Math.pow(-0d, -3) + " If the first argument is negative zero and the second argument is a negative finite odd integer, or the first argument is negative infinity and the second argument is a positive finite odd integer,then the result is negative infinity."); System.out.println(Math.pow(Double.NEGATIVE_INFINITY, 3) + " If the first argument is negative zero and the second argument is a negative finite odd integer, or the first argument is negative infinity and the second argument is a positive finite odd integer,then the result is negative infinity."); System.out.println(Math.pow(-4, 2) + " If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN."); System.out.println(Math.pow(-4, 1) + " If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN."); System.out.println(Math.pow(-4, 0.5) + " If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN."); System.out.println(Math.pow(4, 2) + " If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a double value.");
再上结果:
1.0 If the second argument is positive or negative zero, then the result is 1.0. 1.0 If the second argument is positive or negative zero, then the result is 1.0. 2.0 If the second argument is 1.0, then the result is the same as the first argument. NaN If the second argument is NaN, then the result is NaN. NaN If the first argument is NaN and the second argument is nonzero, then the result is NaN. Infinity If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. Infinity If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. 0.0 If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. 0.0 If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. NaN If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. 0.0 If the first argument is positive zero and the second argument is greater than zero, or the first argument is positive infinity and the second argument is less than zero,then the result is positive zero. 0.0 If the first argument is positive zero and the second argument is greater than zero, or the first argument is positive infinity and the second argument is less than zero,then the result is positive zero. Infinity If the first argument is positive zero and the second argument is less than zero, or the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. Infinity If the first argument is positive zero and the second argument is less than zero, or the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. 0.0111 If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero. -0.0 If the first argument is negative zero and the second argument is a positive finite odd integer, or the first argument is negative infinity and the second argument is a negative finite odd integer,then the result is negative zero. 0.0 The result will get 0.0 if we use int 0 or long 0, expect is -0.0 -0.0 If the first argument is negative zero and the second argument is a positive finite odd integer, or the first argument is negative infinity and the second argument is a negative finite odd integer,then the result is negative zero. Infinity222 If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity. -Infinity If the first argument is negative zero and the second argument is a negative finite odd integer, or the first argument is negative infinity and the second argument is a positive finite odd integer,then the result is negative infinity. -Infinity If the first argument is negative zero and the second argument is a negative finite odd integer, or the first argument is negative infinity and the second argument is a positive finite odd integer,then the result is negative infinity. 16.0 If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN. -4.0 If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN. NaN If the first argument is finite and less than zero if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument if the second argument is finite and not an integer, then the result is NaN. 16.0 If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a double value.
其中,这个例子有点坑,如果不把-0转为浮点数的话,就只能得到0.0,浮点数能得到-0.0
System.out.println(Math.pow(-0, 3) + " The result will get 0.0 if we use int 0 or long 0, expect is -0.0");
原文:http://my.oschina.net/u/921876/blog/403936