strictmath_Java StrictMath nextAfter()方法与示例
strictmath
StrictMath類的nextAfter()方法 (StrictMath Class nextAfter() method)
Syntax:
句法:
public static double nextAfter(double starts , double directions);public static float nextAfter(float starts , double directions);nextAfter() method is available in java.lang package.
nextAfter()方法在java.lang包中可用。
nextAfter(double starts, double directions) method is used to return the double floating-point number adjacent to the first parameter (starts) in the direction of the second parameter (directions).
nextAfter(double starts,double direction)方法用于在第二個參數(directions)的方向上返回與第一個參數(starts)相鄰的double浮點數。
nextAfter(float starts, double directions) method is used to return the float type floating-point number adjacent to the first parameter (starts) in the direction of the second parameter (directions).
nextAfter(float starts,double direction)方法用于在第二個參數(directions)的方向上返回與第一個參數(starts)相鄰的浮點型浮點數。
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):
參數:
start – it represents the initial or starting floating-point value of float or double type.
start –代表float或double類型的初始或起始浮點值。
directions – it represents the value denoting which of the given first parameter neighbors (start's neighbour) or start is returned.
Directions –它表示一個值,該值指示返回給定的第一個參數鄰居(s??tart的鄰居)或start。
Return value:
返回值:
The return type of this method is float / double – it returns the float type floating point number adjacent to start in the direction of second argument.
此方法的返回類型為float / double-返回第二個參數方向上與開始位置相鄰的float類型浮點數。
Note:
注意:
If we pass the same value in both arguments, the method returns the same value.
如果我們在兩個參數中傳遞相同的值,則該方法將返回相同的值。
If we pass Float.MIN_VALUE / Double.MIN_VALUE as the first argument and the second argument contains another value, the method returns the smaller value.
如果我們將Float.MIN_VALUE / Double.MIN_VALUE作為第一個參數傳遞,而第二個參數包含另一個值,則該方法將返回較小的值。
If we pass an infinity as the first argument and the second argument contains another value, the method returns the Float.MAX_VALUE / Double.MAX_VALUE with the sign of the first argument.
如果我們傳遞無窮大作為第一個參數,而第二個參數包含另一個值,則該方法將返回帶有第一個參數符號的Float.MAX_VALUE / Double.MAX_VALUE 。
If we pass Float.MAX_VALUE / Double.MAX_VALUE as the first argument and the second argument contains another value, the method returns the largest value with the sign of the first argument.
如果我們將Float.MAX_VALUE / Double.MAX_VALUE作為第一個參數傳遞,而第二個參數包含另一個值,則該方法將返回帶有第一個參數符號的最大值。
Example:
例:
// Java program to demonstrate the example // of nextAfter() method of StrictMath classpublic class NextAfter {public static void main(String[] args) {// variable declarationsdouble d1 = -2.6;double d2 = 0.0;double d3 = -0.6;double d4 = 7.0 / 0.0;float f1 = -2.6f;float f2 = 0.0f;double d5 = -7.0 / 0.0;// Display previous value of d1,d2,d3 and d4 System.out.println("d1: " + d1);System.out.println("d2: " + d2);System.out.println("d3: " + d3);System.out.println("d4: " + d4);// Display previous value of f1,f2 and d5 System.out.println("f1: " + f1);System.out.println("f2: " + f2);System.out.println("d5: " + d5);System.out.println("nextAfter(double, double): ");// Here , we will get (-2.5 (approx.)) because we are // passing parameter whose value is (-2.6,0.0)System.out.println("StrictMath.nextAfter (d1,d2): " + StrictMath.nextAfter(d1, d2));// Here , we will get (-4.9(approx)) and we are // passing parameter whose value is (0.0,-2.6)System.out.println("StrictMath.nextAfter (d2,d1): " + StrictMath.nextAfter(d2, d1));// Here , we will get (Double.MAX_VALUE) and we are// passing parameter whose value is (7.0/0.0,0.0)System.out.println("StrictMath.nextAfter (d4,d2): " + StrictMath.nextAfter(d4, d2));// Here , we will get (largest value) and we are // passing parameter whose value is (0.0,7.0/0.0)System.out.println("StrictMath.nextAfter (d2,d4): " + StrictMath.nextAfter(d2, d4));System.out.println();System.out.println("nextAfter(float, double): ");// Here , we will get (-2.5 (approx.)) because we are// passing parameter whose value is (-2.6f,0.0)System.out.println("StrictMath. nextAfter (f1,d3): " + StrictMath.nextAfter(f1, d3));// Here , we will get (Float.MAX_VALUE) and we are // passing parameter whose value is (0.0f,-7.0/0.0)System.out.println("StrictMath. nextAfter(f2,d5): " + StrictMath.nextAfter(f2, d5));// Here , we will get (-2.5 (approx)) and we are// passing parameter whose value is (-2.6f,0.0)System.out.println("StrictMath. nextAfter(f1,d2): " + StrictMath.nextAfter(f1, d2));// Here , we will get (smallest value) and we are// passing parameter whose value is (0.0f,-7.0/0.0)System.out.println("StrictMath. nextAfter(f2,d5): " + StrictMath.nextAfter(f2, d5));} }Output
輸出量
d1: -2.6 d2: 0.0 d3: -0.6 d4: Infinity f1: -2.6 f2: 0.0 d5: -Infinity nextAfter(double, double): StrictMath.nextAfter (d1,d2): -2.5999999999999996 StrictMath.nextAfter (d2,d1): -4.9E-324 StrictMath.nextAfter (d4,d2): 1.7976931348623157E308 StrictMath.nextAfter (d2,d4): 4.9E-324nextAfter(float, double): StrictMath. nextAfter (f1,d3): -2.5999997 StrictMath. nextAfter(f2,d5): -1.4E-45 StrictMath. nextAfter(f1,d2): -2.5999997 StrictMath. nextAfter(f2,d5): -1.4E-45翻譯自: https://www.includehelp.com/java/strictmath-nextafter-method-with-example.aspx
strictmath
總結
以上是生活随笔為你收集整理的strictmath_Java StrictMath nextAfter()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lambda python_Python
- 下一篇: l和l_L&T的完整形式是什么?