ulp通信_Java Math类ulp()方法及示例
ulp通信
數學類ulp()方法 (Math class ulp() method)
ulp() method is available in java.lang package.
ulp()方法在java.lang包中可用。
ulp() method is used to return the size of a ulp of the given argument, where, a ulp of the given value is the positive distance between floating-point value and the value next larger in magnitude.
ulp()方法用于返回給定參數的ulp的大小,其中,給定值的ulp是浮點值與下一個幅度較大的值之間的正距離。
ulp() method is a static method, it is accessible with the class name too.
ulp()方法是靜態方法,也可以使用類名進行訪問。
ulp() method does not throw any exception.
ulp()方法不會引發任何異常。
Syntax:
句法:
public static float ulp(float value);public static double ulp(double value);Parameter(s):
參數:
value – represents the float/double floating-point value whose ulp is to be returned.
value –表示要返回其ulp的浮點/雙浮點值。
Return value:
返回值:
The return type of this method is float/double – it returns the size of a ulp.
此方法的返回類型為float / double-返回ulp的大小。
Note:
注意:
If we pass "NaN", it returns the same value (i.e. "NaN").
如果我們傳遞“ NaN”,它將返回相同的值(即“ NaN”)。
If we pass an infinity (+ve or –ve), it returns the infinity.
如果我們傳遞無窮大(+ ve或–ve),它將返回無窮大。
If we pass a zero (0 or -0), it returns the "Float.MIN_VALUE" / "Double.MIN_VALUE".
如果我們傳遞零(0或-0),它將返回“ Float.MIN_VALUE” /“ Double.MIN_VALUE”。
If we pass "Float.MAX_VALUE", it returns the 2^104 and in the case of "Double.MAX_VALUE", it returns the 2^971.
如果我們傳遞“ Float.MAX_VALUE”,則返回2 ^ 104;對于“ Double.MAX_VALUE”,則返回2 ^ 971。
Java程序演示ulp()方法的示例 (Java program to demonstrate example of ulp() method)
// Java program to demonstrate the example of // ulp(float fl) method of Math Classpublic class UlpFloatTypeMethod {public static void main(String[] args) {// declaring the variablesfloat f1 = 0.0f;float f2 = -0.0f;float f3 = 7.0f / 0.0f;float f4 = -7.0f / 0.0f;float f5 = 1285.45f;// Display the valuesSystem.out.println("f1: " + f1);System.out.println("f2: " + f2);System.out.println("f3: " + f3);System.out.println("f4: " + f4);System.out.println("f5: " + f5);// Here , we will get (Float.MIN_VALUE) because // we are passing parameter (0.0)System.out.println("Math.ulp(f1): " + Math.ulp(f1));// Here , we will get (Float.MIN_VALUE) because // we are passing parameter (-0.0)System.out.println("Math.ulp(f2): " + Math.ulp(f2));// Here , we will get (Infinity) because // we are passing parameter (7.0/0.0)System.out.println("Math.ulp(f3): " + Math.ulp(f3));// Here , we will get (Infinity) because // we are passing parameter (-7.0/0.0)System.out.println("Math.ulp(f4): " + Math.ulp(f4));// Here , we will get (2 raised to the power of 104) // because we are passing parameter (1285.45)System.out.println("Math.ulp(f5): " + Math.ulp(f5));} }Output
輸出量
E:\Programs>javac UlpFloatTypeMethod.java E:\Programs>java UlpFloatTypeMethod f1: 0.0 f2: -0.0 f3: Infinity f4: -Infinity f5: 1285.45 Math.ulp(f1): 1.4E-45 Math.ulp(f2): 1.4E-45 Math.ulp(f3): Infinity Math.ulp(f4): Infinity Math.ulp(f5): 1.2207031E-4Example 2:
范例2:
// Java program to demonstrate the example of // ulp(float fl) method of Math Classpublic class UlpFloatTypeMethod {public static void main(String[] args) {// declaring the variablesdouble d1 = 0.0;double d2 = -0.0;double d3 = 7.0 / 0.0;double d4 = -7.0f / 0.0;double d5 = 1285.45;// Display the valuesSystem.out.println("d1: " + d1);System.out.println("d2: " + d2);System.out.println("d3: " + d3);System.out.println("d4: " + d4);System.out.println("d5: " + d5);// Here , we will get (Float.MIN_VALUE) because // we are passing parameter (0.0)System.out.println("Math.ulp(d1): " + Math.ulp(d1));// Here , we will get (Float.MIN_VALUE) because // we are passing parameter (-0.0)System.out.println("Math.ulp(d2): " + Math.ulp(d2));// Here , we will get (Infinity) because // we are passing parameter (7.0/0.0)System.out.println("Math.ulp(d3): " + Math.ulp(d3));// Here , we will get (Infinity) because // we are passing parameter (-7.0/0.0)System.out.println("Math.ulp(d4): " + Math.ulp(d4));// Here , we will get (2 raised to the power of 971) // because we are passing parameter (1285.45)System.out.println("Math.ulp(d5): " + Math.ulp(d5));} }Output
輸出量
E:\Programs>javac UlpMethod.java E:\Programs>java UlpMethod d1: 0.0 d2: -0.0 d3: Infinity d4: -Infinity d5: 1285.45 Math.ulp(d1): 4.9E-324 Math.ulp(d2): 4.9E-324 Math.ulp(d3): Infinity Math.ulp(d4): Infinity Math.ulp(d5): 2.2737367544323206E-13翻譯自: https://www.includehelp.com/java/math-class-ulp-method-with-example.aspx
ulp通信
總結
以上是生活随笔為你收集整理的ulp通信_Java Math类ulp()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 颐和园不含园中园什么意思
- 下一篇: 联想c一10投影机怎么样?效果好吗?