Class ExactMath
- Since:
- 0.8 or earlier
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
multiplyHigh
(int x, int y) static long
multiplyHigh
(long x, long y) static int
multiplyHighUnsigned
(int x, int y) static long
multiplyHighUnsigned
(long x, long y) static double
truncate
(double x) Removes the decimal part (aka truncation or rounds towards zero) of the given double.static float
truncate
(float x) Removes the decimal part (aka truncation or rounds towards zero) of the given float.static int
truncateToUnsignedInt
(double x) Converts the double value to unsigned long with truncation (i.e.static int
truncateToUnsignedInt
(float x) Converts the float value to unsigned int with truncation (i.e.static long
truncateToUnsignedLong
(double x) Converts the double value to unsigned long with truncation (i.e.static long
truncateToUnsignedLong
(float x) Converts the float value to unsigned long with truncation (i.e.static double
unsignedToDouble
(long x) Converts the given unsignedlong
to the closestdouble
value.static float
unsignedToFloat
(long x) Converts the given unsignedlong
to the closestfloat
value.
-
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
roundToIntegralTowardZero
operation (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
roundToIntegralTowardZero
operation (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 ofNaN
andx <= -1
to0
, andx >= 264
to263-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 ofNaN
andx <= -1
to0
, andx >= 264
to263-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 ofNaN
andx <= -1
to0
, andx >= 232
to231-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 ofNaN
andx <= -1
to0
, andx >= 232
to231-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 unsignedlong
to the closestdouble
value.- Parameters:
x
- unsigned integer input, wrapped in a signed integer- Returns:
- the
double
result - Since:
- 25.0
-
unsignedToFloat
public static float unsignedToFloat(long x) Converts the given unsignedlong
to the closestfloat
value.- Parameters:
x
- unsigned integer input, wrapped in a signed integer- Returns:
- the
float
result - Since:
- 25.0
-