java.lang.Math.cbrt(double a)方法實例
java.lang.Math.cbrt(double a) 返回double值的立方根。對於正有限 x, cbrt(-x) == -cbrt(x);也就是說,負值的立方根是負的值的大小的立方根。特殊情況:
如果參數爲NaN,那麼結果爲NaN。
如果參數爲無窮大,那麼結果是相同的符號作爲參數的無窮大。
如果參數是零,那麼結果是相同的符號參數爲零。
計算結果必須在1 ulp確切結果。
聲明
以下是**java.lang.Math.cbrt()**方法的聲明
public static double cbrt(double a)
參數
- a -- a value.
返回值
此方法返回的立方根。
異常
- NA
例子
下面的例子顯示lang.Math.cbrt()方法的使用。
package com.yiibai; import java.lang.*; public class MathDemo { public static void main(String[] args) { // get two double numbers double x = 125; double y = 10; // print the cube roots of three numbers System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x)); System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y)); System.out.println("Math.cbrt(-27)=" + Math.cbrt(-27)); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
Math.cbrt(125)=5.0 Math.cbrt(10)=2.154434690031884 Math.cbrt(-27)=-3.0