JAVAJava |集合2中的lang.StrictMath类

JAVAJava中的lang.StrictMath类|集1 更多的java方法。朗:上数学课

null

13.exp():java。朗,数学。exp(双参数) 方法返回提升为双参数幂的欧拉数。

重要案例:

  • 若参数为NaN,则结果为NaN。
  • 如果参数为+ve无穷大,则结果为+ve无穷大。
  • 如果参数为-ve无穷大,则结果为+ve零。

语法:

public static double exp(double arg)Parameters:arg - argument passed. Returns:Euler’s number raised to the power of passed argument

14.cosh():java。朗,数学。cosh() 方法返回传递的参数的双曲余弦。

特殊情况:

  • 若参数为NaN,则结果为NaN。
  • 如果参数为零,则结果为1.0。
  • 若参数为无穷大,则结果为+ve无穷大。

语法:

public static double cosh(double arg)Parameters:arg - The number whose hyperbolic cosine is to be returned.Returns:the hyperbolic cosine of the argument arg.

15.DecrementAct():java。朗,数学。递减法 方法将传递的参数的值递减1。

语法:

public static int decrementExact(int arg)                orpublic static long decrementExact(long arg)Parameters:arg - argument passed. Returns:return argument decremented by one.Throws:Exception if the result overflows long or int datatype, according to theargumented data type.

解释lang.StrictMath类中exp()、DecrementAct()、cosh()方法的Java代码。

JAVA

// Java program explaining lang.StrictMath class methods
// exp(), decrementExact(), cosh()
import java.math.*;
public class NewClass
{
public static void main(String[] args)
{
// Use of cosh() method
double value = 2 ;
double coshValue = StrictMath.cosh(value);
System.out.println( "Hyperbolic Cosine of " + coshValue);
System.out.println( "" );
// Use of decrementExact() method
int result = StrictMath.decrementExact( 3051 );
System.out.println( "Use of decrementExact() : " + result);
System.out.println( "" );
// Use of exp() method
// declare the exponent to be used
double exponent = 34 ;
// raise e to exponent declared
double expVal = StrictMath.exp(exponent);
System.out.println( "Value of exp : " + expVal);
}
}


输出:

Using addExact() : 9acos value of Asini : NaNacos value of Asinj : 0.054858647341251204cube root : 6.0

16.log10():java。朗,数学。log10() 方法返回所传递参数的base10对数值。

Syntax:public static double log(double arg)Parameters:arg - argument passed. Returns:base10 logarithmic value of the argument passed.

17.pow():java。朗,数学。战俘(双b,双e) 方法将值返回为 B E

Syntax:public static double pow(double b, double e)Parameters:b : basee : exponent Returns:value as baseexponent

18.incrementExact():java。朗,数学。递增精确() 方法通过递增参数的值来返回参数。

Syntax:public static int incrementExact(int arg)               orpublic static long incrementExact(long arg)Parameters:arg - the argumentReturns:incremented value of the argument

解释lang.StrictMath类中incrementExact()、log10()、pow()方法的JAVA代码。

JAVA

// Java program explaining lang.MATH class methods
// incrementExact(), log10(), pow()
import java.lang.*;
public class NewClass
{
public static void main(String[] args)
{
// Use of incrementExact() method
int f1 = 30 , f2 = - 56 ;
f1 = StrictMath.incrementExact(f1);
System.out.println( "Incremented value of f1 : " + f1);
f2 = StrictMath.incrementExact(f2);
System.out.println( "Incremented value of f2 : " + f2);
System.out.println( "" );
// Use of log10() method
double value = 10 ;
double logValue = StrictMath.log10(value);
System.out.println( "Log10 value of 10 : " + logValue);
System.out.println( "" );
// Use of pow() method
double b = 10 , e = 2 ;
double power = StrictMath.pow(b, e);
System.out.println( "Use of pow() : " + power);
}
}


输出:

Incremented value of f1 : 31Incremented value of f2 : -55Log10 value of 10 : 1.0Use of pow() : 100.0

19.signum():java。朗,数学。符号() 方法返回传递的参数的符号值。

                                    -1    if x < 0                    signum fun(x) =  0    if x = 0                                     1    if x > 0

注:

结果为NaN,如果通过,则参数为NaN。

语法:

public static double signum(double x)               orpublic static float signum(float x)Parameters:x - the argument whose signum value we needReturns:signum value of x

20.max():java。朗,数学。最大值(双v1,双v2) 方法返回传递的两个参数值中的较大值。 这种方法只使用震级进行比较,不考虑任何符号。

语法:

public static double max(double v1, double v2)Parameters:v1 - first valuev2 - second valueReturns:v1 or v2 based on which number is greater.It can return either of the two if v1 = v2. 

21.round():java。朗,数学。第(轮) 方法将传递的参数四舍五入到最接近的小数位数。

注: 如果参数为NaN,则结果为0。

语法:

public static long round(long arg)             orpublic static double round(double arg)Parameters:arg - argument needs to round off Returns:round off value of the argument

解释lang.StrictMath类中signum()、round()、max()方法的Java代码。

JAVA

// Java code explaining the lang.StrictMath Class methods
// signum(), round(), max()
import java.lang.*;
public class NewClass
{
public static void main(String args[])
{
// Use of signum() method
double x = 10.4556 , y = - 23.34789 ;
double signm = StrictMath.signum(x);
System.out.println( "Signum of 10.45 = " + signm);
signm = StrictMath.signum(y);
System.out.println( "Signum of -23.34 = " + signm);
System.out.println( "" );
// Use of round() method
double r1 = StrictMath.round(x);
System.out.println( "Round off 10.4556 = " + r1);
double r2 = StrictMath.round(y);
System.out.println( "Round off 23.34789 = " + r2);
System.out.println( "" );
// Use of max() method on r1 and r2
double m = StrictMath.max(r1, r2);
System.out.println( "Max b / w r1 and r2 = " + r2);
}
}


输出:

Signum of 10.45  = 1.0Signum of -23.34 = -1.0Round off 10.4556  = 10.0Round off 23.34789 = -23.0Max b/w r1 and r2 = -23.0

22.ulp():java。朗,数学。ulp() 方法返回 最小精度单位(ulp) 即两个浮点数之间的最小距离。 这里,它是参数和下一个较大值之间的最小距离。

语法:

public static double ulp(double arg)              orpublic static float ulp(float arg)Parameters:arg - argument passed. Returns:least distance b/w the argument and next larger value.

23.log1p():java。朗,数学。log1p() 方法返回(传递的参数+1)的自然日志。

语法:

public static double log1p(double arg)Parameters:arg - the argumentReturns:log of (argument + 1).This result is within 1 unit in the last place of exact result.

解释lang.StrictMath类中ulp()、log1p()方法的Java代码。

JAVA

// Java code explaining the lang.StrictMath Class methods
// ulp(), log1p()
import java.lang.*;
public class NewClass
{
public static void main(String args[])
{
// Use of ulp() method
double x = 34.652 , y = - 23.34789 ;
double u = StrictMath.ulp(x);
System.out.println( "ulp of 34.652 : " + u);
u = StrictMath.ulp(y);
System.out.println( "ulp of -23.34789 : " + u);
System.out.println( "" );
// Use of log() method
double l = 99 ;
double l1 = StrictMath.log1p(l);
System.out.println( "Log of (1 + 99) : " + l1);
l1 = StrictMath.log( 100 );
System.out.println( "Log of 100     : " + l1);
}
}


输出:

ulp of 34.652    : 7.105427357601002E-15ulp of -23.34789 : 3.552713678800501E-15Log of (1 + 99)  : 4.605170185988092Log of 100       : 4.605170185988092
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享