java.lang.Math.pow 实例

先上实例:

        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");
时间: 2024-08-16 19:36:30

java.lang.Math.pow 实例的相关文章

java.lang.Math中的基本方法

java.lang.Math类提供的方法都是static的,“静态引入 ”使得不必每次在调用类方法时都在方法前写上类名:             import static java.lang.Math.*; 这样在调用Math的方法时就能够简单地写出方法名,比如:             cos(radians); ---------------------------------------------------------- 1.基本方法: abs, max, min, ceil, fl

java.lang.Math类

Java.lang.Math类用法实例教程 - java.lang.Math 类包含的方法进行基本的数字操作,如基本的指数,对数,平方根和三角函数等. 以下是java.lang.Math类的声明: 1 public final class Math extends Object static double abs(double a) 此方法返回一个绝对值 static double cbrt(double a)此方法返回一个double值的立方根. static double random()

java.lang math 类

我们在编程的过程中,经常对一些数字进行数学操作,比如我们想要求绝对值或余弦什么的.那这些方法是否需要我们自己实现吗?其实在 java.lang 里的 Math 类Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函数.我们就来学习一下吧! 先认识一些方法吧: 方法 返回值 功能描述sin(double numvalue) double 计算角 numvalue 的正弦值cos(double numvalue) double 计算角 numvalue 的余弦值acos(do

java.lang.Math

package com.etc.usual; public class TestMath { public static void main(String[] args) { // TODO Auto-generated method stub //字段摘要 System.out.println(Math.PI);//3.141592653589793 System.out.println(Math.E); //2.718281828459045 //abs System.out.println

java.lang.Math中次方与开次方

开方数3 要开放的次数4 被开方数应该为3的4次方=81 次方: Math.pow(3,4)=81 开次方 Math.pow(81.0, 1.0/4)=3

【java】java.lang.Math:public static long round(double a)和public static int round(float a)

1 package math; 2 3 public class TestMath_round { 4 public static void main(String[] args) { 5 System.out.println(Math.round(0.5));//1 6 System.out.println(Math.round(-0.5));//0 7 System.out.println(Math.round(-0.501));//-1 8 //Math类的四舍五入方法round进行负数操

Math.pow用法及实现探究

pow函数在java.lang.Math类中,是求次方的函数,定义为: public static double pow(double a, double b): 即求a的b次方,例如: public static void main(String[] args) { double a = 2.0D; double b = 4.0D; double r = Math.pow(a, b); System.out.println(r); //输出为16.0 } 查看源码,发现其实现调用了Strict

java之Math

一.Math类 java.lang.Math提供了一系列静态方法用于科学计算:其方法的参数和返回值类型一般为double型. abs     绝对值 acos,asin,atan,cos,sin,tan  三角函数 sqrt     平方根 pow(double a,doble b)     a的b次幂 log    自然对数 exp    e为底指数 max(double a,double b) min(double a,double b) random()      返回0.0到1.0的随机

java能不能自己写一个类叫java.lang.System/String正确答案

原文: http://www.wfuyu.com/php/22254.html 未做测试 ! 最近学习了下java类加载相干的知识.然后看到网上有1道面试题是 能不能自己写个类叫java.lang.System? 网上提供的答案:通常不可以,但可以采取另类方法到达这个需求.所谓的另类方法指自己写个类加载器来加载java.lang.System到达目的. 首先表明下我的观点.上述答案完全是误导读者,是不正确的答案.我就疑惑了网上怎样把这类完全不正确的搜索结果排在前面,而且几近搜到的都是这类不正确的