Class ExactMath
- Since:
- 0.8 or earlier
-
Method Summary
Modifier and TypeMethodDescriptionstatic intmultiplyHigh(int x, int y) static longmultiplyHigh(long x, long y) static intmultiplyHighUnsigned(int x, int y) static longmultiplyHighUnsigned(long x, long y) static doubletruncate(double x) Removes the decimal part (aka truncation or rounds towards zero) of the given double.static floattruncate(float x) Removes the decimal part (aka truncation or rounds towards zero) of the given float.static inttruncateToUnsignedInt(double x) Converts the double value to unsigned long with truncation (i.e.static inttruncateToUnsignedInt(float x) Converts the float value to unsigned int with truncation (i.e.static longtruncateToUnsignedLong(double x) Converts the double value to unsigned long with truncation (i.e.static longtruncateToUnsignedLong(float x) Converts the float value to unsigned long with truncation (i.e.static doubleunsignedToDouble(long x) Converts the given unsignedlongto the closestdoublevalue.static floatunsignedToFloat(long x) Converts the given unsignedlongto the closestfloatvalue.
-
Method Details
-
multiplyHigh
public static int multiplyHigh(int x, int y) - Since:
- 0.8 or earlier
-
multiplyHighUnsigned
public static int multiplyHighUnsigned(int x, int y) - Since:
- 0.8 or earlier
-
multiplyHigh
public static long multiplyHigh(long x, long y) - Since:
- 0.8 or earlier
-
multiplyHighUnsigned
public static long multiplyHighUnsigned(long x, long y) - Since:
- 0.8 or earlier
-
truncate
public static float truncate(float x) Removes the decimal part (aka truncation or rounds towards zero) of the given float.This corresponds to the IEEE 754
roundToIntegralTowardZerooperation (IEEE Std 754-2008, section 5.9, page 41).- Since:
- 21.1
-
truncate
public static double truncate(double x) Removes the decimal part (aka truncation or rounds towards zero) of the given double.This corresponds to the IEEE 754
roundToIntegralTowardZerooperation (IEEE Std 754-2008, section 5.9, page 41).- Since:
- 21.1
-
truncateToUnsignedLong
public static long truncateToUnsignedLong(double x) Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation ofNaNandx <= -1to0, andx >= 264to263-1(-1).Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (
x <= -1) and overflow (x >= 0x1p64) first.- Parameters:
x- input value- Returns:
- the unsigned integer result, wrapped in a signed integer
- Since:
- 25.0
-
truncateToUnsignedLong
public static long truncateToUnsignedLong(float x) Converts the float value to unsigned long with truncation (i.e. rounding towards zero) and saturation ofNaNandx <= -1to0, andx >= 264to263-1(-1).Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (
x <= -1f) and overflow (x >= 0x1p64f) first.- Parameters:
x- input value- Returns:
- the unsigned integer result, wrapped in a signed integer
- Since:
- 25.0
-
truncateToUnsignedInt
public static int truncateToUnsignedInt(double x) Converts the double value to unsigned long with truncation (i.e. rounding towards zero) and saturation ofNaNandx <= -1to0, andx >= 232to231-1(-1).Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (
x <= -1) and overflow (x >= 0x1p32) first.- Parameters:
x- input value- Returns:
- the unsigned integer result, wrapped in a signed integer
- Since:
- 25.0
-
truncateToUnsignedInt
public static int truncateToUnsignedInt(float x) Converts the float value to unsigned int with truncation (i.e. rounding towards zero) and saturation ofNaNandx <= -1to0, andx >= 232to231-1(-1).Non-saturating (e.g. trapping) behavior can be implemented by checking the input for NaN, underflow (
x <= -1) and overflow (x >= 0x1p64) first.- Parameters:
x- input value- Returns:
- the unsigned integer result, wrapped in a signed integer
- Since:
- 25.0
-
unsignedToDouble
public static double unsignedToDouble(long x) Converts the given unsignedlongto the closestdoublevalue.- Parameters:
x- unsigned integer input, wrapped in a signed integer- Returns:
- the
doubleresult - Since:
- 25.0
-
unsignedToFloat
public static float unsignedToFloat(long x) Converts the given unsignedlongto the closestfloatvalue.- Parameters:
x- unsigned integer input, wrapped in a signed integer- Returns:
- the
floatresult - Since:
- 25.0
-