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 Class
public class UlpFloatTypeMethod {
public static void main(String[] args) {
// declaring the variables
float 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 values
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 (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-4

Example 2:

范例2:

// Java program to demonstrate the example of 
// ulp(float fl) method of Math Class
public class UlpFloatTypeMethod {
public static void main(String[] args) {
// declaring the variables
double 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 values
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);
// 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通信

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/378080.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机公式column,函数公式的左膀右臂:ROW、COLUMN函数知多少

一个公式生成乘法口诀表演示的公式中用到了两个函数:ROW和COLUMN,这两个函数的用途非常广泛,可以配合其他函数实现很多功能(尤其是和VLOOKUP函数),另外和这两个函数相似的还有ROWS和COLUMNS函数,也顺便介绍下。函数说明…

apache2.4.x三种MPM介绍

三种MPM介绍 Apache 2.X 支持插入式并行处理模块,称为多路处理模块(MPM)。在编译apache时必须选择也只能选择一个MPM,对类UNIX系统,…

LeetCode 15. 三数之和 思考分析(双指针解)

目录初解:未考虑去重二解:未考虑去重位置三解:AC题目:给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a b c 0 ?请你找出所有满足条件且…

十、非规则组织分析及其数学模型——锯齿形斜纹组织

锯齿形斜纹组织图: 分析: 前半齿长度k,表示山谷到山峰的列数,也就是锯齿的宽度; 锯齿飞数s,表示山峰到山峰的行数,也就是锯齿的高度。 起始点相差4格,也就是第一部分整体向上移动…

Linq lamdba GroupJoin外连接示例

其实用from..Linq语句做外连接简单而且便于理解&#xff0c;我个人使用lamdba纯粹是技术上的追求吧 DataTable exceldtnew DataTable();DataTable nomacdtnew DataTable();exceldt exceldt.AsEnumerable().GroupJoin(nomacdt.AsEnumerable(), a > a.Field<String>(&q…

ajax为什么有时候不行,为什么不能用ajax调用

Ajax取值时出现未知的运行时错误的解决方法在Ajax里经常会通过innerHTML来改变界面&#xff0c;这个比使用DOM要简单一些。比如&#xff1a;element.innerHTML "put code here"不过&#xff0c;在IE中&#xff0c;有时候会出现"未知的运行时错误(unknown runti…

Java Hashtable size()方法与示例

哈希表类size()方法 (Hashtable Class size() method) size() method is available in java.util package. size()方法在java.util包中可用。 size() method is used to return the number of key-value pairs that exist in this Hashtable. size()方法用于返回此哈希表中存在…

十一、非规则组织分析及其数学模型——芦席斜纹组织

芦席斜纹组织&#xff1a; 该组织是由左斜和右斜有机的结合在一块的&#xff0c;因为其外观酷似芦席故称之为芦席斜纹组织。 织物组织效果&#xff1a; 所需参数&#xff1a; 其基层组织采用双面加强型斜纹&#xff0c;即分子和分母是相同的组织点&#xff0c;例如2上2下(2个经…

LeetCode 18. 四数之和 思考分析(双指针解)

目录需要注意的几点1、去除剪枝操作2、去重操作的细节code以及效果&#xff1a;题目给定一个包含 n 个整数的数组 nums 和一个目标值 target&#xff0c;判断 nums 中是否存在四个元素 a&#xff0c;b&#xff0c;c 和 d &#xff0c;使得 a b c d 的值与 target 相等&#…

图解DotNet框架之一:编译与执行引擎(上)

众所周知,DotNet框架是非常庞大的,光项目创建时的种类就有WPF,WCF,WF这三种最新的技术,还有以前的Web,WinForm,Service,Mobile等等. 这么复杂和庞大的框架,用文字来描述是远远不够的,所以我准备写一系列图文并茂的文章,把我所知道的所有Net框架中的东西全部串联起来,希望可以给…

【Kissy WaterFall】实行手动加载数据

前言&#xff1a;由于Kissy WaterFall默认是监听滚动事件来实现数据动态加载的&#xff0c;但是有一些情况要用到手动加载数据。以下是使用Kissy WaterFall实现手动加载数据的方法。 最终实现效果&#xff1a;点击”逛更多的商店“会动态加载数据 步骤&#xff1a; 当一页数据加…

web服务器文档根目录在哪里,web服务器根目录在哪

web服务器根目录在哪 内容精选换一换SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(访问方式为HTTPS)&#xff0c;实现数据信息在客户端和服务器之间的加密传输&#xff0c;可以防止数据信息的泄露。SSL保证了双方传递信息的安全性&#xff0c;而且用户可以通过…

console java_Java Console writer()方法与示例

console java控制台类writer()方法 (Console Class writer() method) writer() method is available in java.io package. writer()方法在java.io包中可用。 writer() method is used to get a distinct PrintWriter object linked with this Console. writer()方法用于获取与此…

二、图片加载与保存

一、基本概念 1&#xff0c;什么是图片&#xff1f; 答&#xff1a;图像是结构化存储的数据信息 2&#xff0c;图像的属性 答&#xff1a;1、通道数目&#xff0c;2、宽与高&#xff0c;3、像素数据&#xff0c;4、图像类型 二、加载显示图像并保存 import cv2 import nump…

LeetCode 206. 反转链表 思考分析

题目 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶: 你可以迭代或递归地反转链表。你能否用两种方法解决这道题&#xff1f; 迭代双指针 从某公众号&#xff08;代码随想录&#xff09;搬过来的gif图&…

hdu 2846 Repository 字典树的变形

Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)                  Total Submission(s): 1129 Accepted Submission(s): 382 Problem DescriptionWhen you go shopping, you can search in repository…

怎样看虚拟主机的服务器,虚拟主机怎么查看服务器类型

虚拟主机怎么查看服务器类型 内容精选换一换使用华为云提供的公共镜像制作私有镜像时&#xff0c;您需先购买云主机等云资源时镜像选择公共镜像、云服务器类型建议统一选择“s3 (通用计算型)”&#xff0c;在云主机安装部署完商品&#xff0c;然后参照以下方式进行私有镜像制作…

Win32动态库 Lib文件哪去了

最近使用SQLite&#xff0c;用源文件.c和.h编译SQLite的动态库&#xff0c;编译后发现没有Lib文件。 原来&#xff1a;SQLite的.c文件没有引用.h文件&#xff0c;添加引用&#xff0c;编译&#xff0c;Lib文件有了。转载于:https://www.cnblogs.com/yunuoyuhan/p/3204457.html

console java_Java Console format()方法与示例

console java控制台类format()方法 (Console Class format() method) format() method is available in java.io package. format()方法在java.io包中可用。 format() method is used to write the formatted string to this Console with the help of the given string format…

Anaconda自带Python编译器Jupyter Notebook显示代码行数

ESC&#xff1a;进入命令行模式&#xff1b;按下H即可显示各种快捷键信息 Enter&#xff1a;进入编辑模式 方法一&#xff1a;命令方法 一、点击代码段&#xff0c;按ESC&#xff0c;使代码段显示蓝色&#xff0c;进入命令行模式 二、按下ShiftL&#xff0c;显示代码行数 方法…