博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
strictmath_Java StrictMath ulp()方法与示例
阅读量:2530 次
发布时间:2019-05-11

本文共 5520 字,大约阅读时间需要 18 分钟。

strictmath

StrictMath类ulp()方法 (StrictMath Class ulp() method)

Syntax:

句法:

public static double ulp(double do);    public static float ulp(float fl);
  • ulp() Method is available in java.lang package.

    ulp()方法在java.lang包中可用。

  • ulp(double do) Method is used to return the size of an ulp of the given argument in the method. In this method, an ulp of the given double value parameter is the positive distance between double floating-point value and the given argument double value next larger in magnitude.

    ulp(double do)方法用于返回方法中给定参数的ulp的大小。 在此方法中,给定双值参数的ulp是双浮点值与下一个幅度较大的给定自变量double值之间的正距离。

  • ulp(float fl) Method is used to return the size of an ulp of the given argument in the method. In this method, an ulp of the given float value parameter is the positive distance between float floating-point value and the given argument float value next larger in magnitude.

    ulp(float fl)方法用于返回方法中给定参数的ulp的大小。 在此方法中,给定浮点值参数的ulp是浮点浮点值与给定自变量浮点值之间的正距离,其大小随后更大。

  • 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):

参数:

  • float / double – represents the value represents the double floating point value whose ulp is to be returned.

    float / double-表示该值表示要返回其ulp的double浮点值。

Return value:

返回值:

The return type of the method is float / double, it returns the size of an ulp of the given parameter and return value is of float / double type.

该方法的返回类型为float / double ,它返回给定参数的ulp的大小,返回值为float / double类型。

Note:

注意:

  • If we pass NaN, the method returns the same value (i.e. NaN).

    如果我们通过NaN,则该方法返回相同的值(即NaN)。

  • If we pass an infinity (positive or negative), the method returns the positive infinity.

    如果我们传递无穷大(正数或负数),则该方法将返回正无穷大。

  • If we pass zero (positive or negative), the method returns the Float.MIN_VALUE / Double.MIN_VALUE.

    如果传递零(正数或负数),则该方法返回Float.MIN_VALUE / Double.MIN_VALUE 。

  • If we pass Float.MAX_VALUE, the method returns the 2 raised to the power of 104 and if we pass Double.MAX_VALUE, the method returns the 2 raised to the power of 971.

    如果传递Float.MAX_VALUE ,则该方法返回2的幂,以104的幂表示;如果传递Double.MAX_VALUE ,则该方法返回2的幂为971的幂。

Example:

例:

// Java program to demonstrate the example // of signum() method of StrictMath classpublic class Ulp {
public static void main(String[] args) {
// variable declarations double d1 = 0.0; double d2 = -0.0; double d3 = 7.0 / 0.0; double d4 = -7.0 / 0.0; double d5 = 1285.45; float f1 = 0.0f; float f2 = -0.0f; float f3 = 7.0f / 0.0f; float f4 = -7.0f / 0.0f; float f5 = 1285.45f; System.out.println(); System.out.println("ulp(double d:)"); // Display previous value of d1,d2,d3 ,d4and d5 System.out.println("d1:" + d1); System.out.println("d2: " + d2); System.out.println("d3: " + d3); System.out.println("d4: " + d4); System.out.println("d5: " + d5); // Display previous value of f1,f2,f3 ,f4and d5 System.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 (Double.MIN_VALUE) because // we are passing parameter (0.0) System.out.println("StrictMath.ulp(d1): " + StrictMath.ulp(d1)); // Here , we will get (Double.MIN_VALUE) because // we are passing parameter (-0.0) System.out.println("StrictMath.ulp(d2): " + StrictMath.ulp(d2)); // Here , we will get (Infinity) because // we are passing parameter (7.0/0.0) System.out.println("StrictMath.ulp(d2): " + StrictMath.ulp(d3)); // Here , we will get (Infinity) because // we are passing parameter (-7.0/0.0) System.out.println("StrictMath.ulp(d2): " + StrictMath.ulp(d4)); // Here , we will get (2 raised to the power of 971) because // we are passing parameter (1285.45) System.out.println("StrictMath.ulp(d5): " + StrictMath.ulp(d5)); System.out.println(); System.out.println("ulp(float fl:)"); // Here , we will get (Float.MIN_VALUE) because // we are passing parameter (0.0) System.out.println("StrictMath.ulp(f1): " + StrictMath.ulp(f1)); // Here , we will get (Float.MIN_VALUE) because // we are passing parameter (-0.0) System.out.println("StrictMath.ulp(f2): " + StrictMath.ulp(f2)); // Here , we will get (Infinity) because // we are passing parameter (7.0/0.0) System.out.println("StrictMath.ulp(f3): " + StrictMath.ulp(f3)); // Here , we will get (Infinity) because // we are passing parameter (-7.0/0.0) System.out.println("StrictMath.ulp(f4): " + StrictMath.ulp(f4)); // Here , we will get (2 raised to the power of 971) because // we are passing parameter (1285.45) System.out.println("StrictMath.ulp(f5): " + StrictMath.ulp(f5)); }}

Output

输出量

ulp(double d:)d1:0.0d2: -0.0d3: Infinityd4: -Infinityd5: 1285.45f1: 0.0f2: -0.0f3: Infinityf4: -Infinityf5: 1285.45StrictMath.ulp(d1): 4.9E-324StrictMath.ulp(d2): 4.9E-324StrictMath.ulp(d2): InfinityStrictMath.ulp(d2): InfinityStrictMath.ulp(d5): 2.2737367544323206E-13ulp(float fl:)StrictMath.ulp(f1): 1.4E-45StrictMath.ulp(f2): 1.4E-45StrictMath.ulp(f3): InfinityStrictMath.ulp(f4): InfinityStrictMath.ulp(f5): 1.2207031E-4

翻译自:

strictmath

转载地址:http://fhxzd.baihongyu.com/

你可能感兴趣的文章
Http协议的学习
查看>>
【转】轻松记住大端小端的含义(附对大端和小端的解释)
查看>>
设计模式那点事读书笔记(3)----建造者模式
查看>>
交换机划分Vlan配置
查看>>
yum安装Elasticsearch5.x
查看>>
正则表达式
查看>>
Python模块_json & pickle模块
查看>>
Python 模块之_os模块_os是与操作系统交互的接口
查看>>
通通玩blend美工(1)——荧光Button
查看>>
[UWP]了解模板化控件(8):ItemsControl
查看>>
使用JustDecompile修改程序集
查看>>
SQLServer 分组查询相邻两条记录的时间差
查看>>
Swift语言指南(一)--语言基础之常量和变量
查看>>
关于webpack的使用
查看>>
Windows 2008 R2上配置IIS7或IIS7.5中的URLRewrite(URL重写)实例
查看>>
浅析java垃圾回收机制
查看>>
彻底理解线性筛选法
查看>>
Java Socket总结
查看>>
法语学习笔记
查看>>
使用css的类名交集复合选择器 《转》
查看>>