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.pswp.cn/news/378080.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378080.shtml
英文地址,請注明出處:http://en.pswp.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;顯示代碼行數 方法…