[英]fixed floating point calculations in Java
在Java中,我需要一些提示來聲明浮點變量,該變量在所有虛擬機中均是唯一運行的,並在所有機器(移動機和PC)中顯示唯一的浮點數
您可以將strictfp
關鍵字用於類聲明或變量:
public strictfp class MyFPclass {
// ... contents of class here ...
}
Java包java.lang.Math類包含以下strictfp方法:
public static strictfp double abs(double);
public static strictfp int max(int, int);
public static strictfp long max(long, long);
public static strictfp float max(float, float);
public static strictfp double max(double, double);
public static strictfp int min(int, int);
我可以為此建議兩個班級
Random類的方法通常以更方便的形式生成隨機數,但是需要創建一個對象,這有時很不方便。 相反,Math.random()方法產生一個雙精度值,有時必須將其轉換並轉換為所需的形式。 這是Math.random全局性和來自Random類的更直接有用的數字之間的折衷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.