strictmath
StrictMath类scalb()方法 (StrictMath Class scalb() method)
Syntax:
句法:
public static double scalb(double do , int sf);
public static float scalb(float fl , int sf);
scalb(double do , int sf) method is used to return do* 2 raised to the power of sf rounded as an argument as passed in the method.
scalb(double do,int sf)方法用于将do * 2提升为sf的幂,该整数作为方法中传递的参数进行舍入。
scalb(double do , int sf) –
scalb(double do,int sf) –
- If the exponent lies in between Double.MIN_EXPONENT and Double.MAX_EXPONENT and in that case the result is exactly calculated.
- 如果指数位于Double.MIN_EXPONENT和Double.MAX_EXPONENT之间,则在这种情况下,将精确计算结果。
- If the exponent answer would be greater than Double.MAX_EXPONENT and in that case infinity is returned.
- 如果指数答案大于Double.MAX_EXPONENT ,则返回无穷大。
- scalb(float fl , int sf) method is used to return fl* 2 raised to the power of sf rounded as an argument as passed in the method.
- scalb(float fl,int sf)方法用于返回fl * 2 ,该值被提升为sf的幂,该整数作为方法中传递的参数进行舍入。
scalb(float fl , int sf) –
scalb(float fl,int sf) –
- If the exponent lies in between Float.MIN_EXPONENT and Float.MAX_EXPONENT and in that case the result is exactly calculated.
- 如果指数位于Float.MIN_EXPONENT和Float.MAX_EXPONENT之间, 那么在这种情况下,结果将被精确计算。
- If the exponent answer would be greater than Float.MAX_EXPONENT and in that case infinity is returned.
- 如果指数答案大于Float.MAX_EXPONENT ,则返回无穷大。
These methods don't throw an exception.
这些方法不会引发异常。
These are static methods, it is accessible with the class name and, if we try to access these methods with the class object then we will not get any error.
这些是静态方法,可以通过类名进行访问,如果尝试使用类对象访问这些方法,则不会出现任何错误。
Parameter(s):
参数:
In the first case, scalb(double do , int sf) -
在第一种情况下, scalb(double do,int sf) -
- double do - This parameter represents the double number to be scaled by the power of 2.
- double do-此参数表示要以2的幂进行缩放的双精度数。
- int sf - This argument represents integer type number power of 2 used to scale do.
- int sf-此参数表示用于定标do的整数类型的2的幂。
In the second case, scalb(float fl , int sf) -
在第二种情况下, scalb(float fl,int sf) -
- float fl - This argument represents the float type number to be scaled by the power of 2.
- float fl-此参数表示以2的幂进行缩放的float类型号。
- int sf - This argument represents integer number power of 2 used to scale fl.
- int sf-此参数表示2的整数次方,用于缩放fl。
Return value:
返回值:
In the first case, the return type of this method is double it returns the do* 2 raised to the power of sf.
在第一种情况下,此方法的返回类型为double,它会将do * 2提升为sf的幂。
In the second case, the return type of this method is float it returns the fl* 2 raised to the power of sf.
在第二种情况下,此方法的返回类型为float,它将返回提升为sf的fl * 2 。
Example:
例:
// Java program to demonstrate the example
// of scalb () method of StrictMath class
public class Scalb {
public static void main(String[] args) {
// variable declarations
float f1 = -0.0f;
float f2 = -7.0f / 0.0f;
float f3 = 20.0f;
double d1 = -0.0;
double d2 = -7.0 / 0.0;
double d3 = 20.0;
int i = 6;
System.out.println("scalb(double do, int i): ");
// Here , we will get (-0.0) because we are passing
// parameter whose value is (-0.0f,6)
System.out.println("StrictMath.scalb( f1,i): " + StrictMath.scalb(f1, i));
// Here , we will get (-Infinity) and we are passing parameter
// whose value is (-Infinity,6)
System.out.println("StrictMath.scalb( f2,i): " + StrictMath.scalb(f2, i));
// Here , we will get (20.0f * 2 raised to the power of 6) and
// we are passing parameter whose value is (20.0f,6)
System.out.println("StrictMath.scalb( f3,i): " + StrictMath.scalb(f3, i));
System.out.println();
System.out.println("scalb(double do, int i): ");
// Here , we will get (-0.0) because we are passing
// parameter whose value is (-0.0,6)
System.out.println("StrictMath.scalb( d1,i): " + StrictMath.scalb(d1, i));
// Here , we will get (-Infinity) and we are passing parameter
// whose value is (-Infinity,6)
System.out.println("StrictMath.scalb( d2,i): " + StrictMath.scalb(d2, i));
// Here , we will get (20.0 * 2 raised to the power of 6.0) and
// we are passing parameter whose value is (20.0,6)
System.out.println("StrictMath.scalb( d3,i): " + StrictMath.scalb(d3, i));
}
}
Output
输出量
scalb(double do, int i):
StrictMath.scalb( f1,i): -0.0
StrictMath.scalb( f2,i): -Infinity
StrictMath.scalb( f3,i): 1280.0scalb(double do, int i):
StrictMath.scalb( d1,i): -0.0
StrictMath.scalb( d2,i): -Infinity
StrictMath.scalb( d3,i): 1280.0
翻译自: https://www.includehelp.com/java/strictmath-scalb-method-with-example.aspx
strictmath