Class JSCompDoubles
- java.lang.Object
-
- com.google.javascript.jscomp.base.JSCompDoubles
-
public final class JSCompDoubles extends java.lang.Object
Basic double functions used by JSComp.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
ecmascriptToInt32(double number)
The ECMAScript ToInt32 abstract operation.static int
ecmascriptToUint32(double number)
The ECMAScript ToUint32 abstract operation.static boolean
isAtLeastIntegerPrecision(double x)
Does `x` have precision down to the "ones column"?static boolean
isEitherZero(double x)
Is `x` positive or negative zero?static boolean
isExactInt32(double x)
Can a 32 bit int exactly represent `x`?static boolean
isExactInt64(double x)
Can a 64 bit int exactly represent `x`?static boolean
isMathematicalInteger(double x)
Does `x` exactly represent an value with no fractional part?static boolean
isNegative(double x)
Does `x` carry a negative sign?static boolean
isPositive(double x)
Does `x` not carry a negative sign?
-
-
-
Method Detail
-
isExactInt32
public static boolean isExactInt32(double x)
Can a 32 bit int exactly represent `x`?Many double values are not exact integers. Many that are integers are too large to fit into a Java int.
This function does not guarantee that a value can be round-tripped from double to int to double and have an identical bit pattern. Notably, 0.0 and -0.0 both represent exactly 0.
-
isExactInt64
public static boolean isExactInt64(double x)
Can a 64 bit int exactly represent `x`?Many double values are not exact integers. Many that are integers are too large to fit into a Java long.
This function does not guarantee that a value can be round-tripped from double to long to double and have an identical bit pattern. Notably, 0.0 and -0.0 both represent exactly 0.
-
isMathematicalInteger
public static boolean isMathematicalInteger(double x)
Does `x` exactly represent an value with no fractional part?The value may be too large to fit in a primitive integral type, such as long.
Returns false for NaN and Infinity.
This should behave identically to Guava
DoubleMath.isMathematicalInteger
but is J2CL compatible.
-
isAtLeastIntegerPrecision
public static boolean isAtLeastIntegerPrecision(double x)
Does `x` have precision down to the "ones column"?A double can hold exact integer values that are very large, but to do so it may loose precision at the scale of "ones". That is "largeDouble + 1.0 == largeDouble" may be true.
Returns false for NaN and Infinity.
-
isNegative
public static boolean isNegative(double x)
Does `x` carry a negative sign?Because -0.0 == 0.0, it is not enough to check `x < 0.0` to determine if a double is negative. This function identifies the -0.0 case.
-
isPositive
public static boolean isPositive(double x)
Does `x` not carry a negative sign?Because -0.0 == 0.0, it is not enough to check `x < 0.0` to determine if a double is negative. This function identifies the -0.0 case.
-
isEitherZero
public static boolean isEitherZero(double x)
Is `x` positive or negative zero?
-
ecmascriptToInt32
public static int ecmascriptToInt32(double number)
The ECMAScript ToInt32 abstract operation.See https://262.ecma-international.org/5.1/#sec-9.5
-
ecmascriptToUint32
public static int ecmascriptToUint32(double number)
The ECMAScript ToUint32 abstract operation.Java has no uint types, so the caller must remember to treat the returned bits as a uint.
See https://262.ecma-international.org/5.1/#sec-9.6
-
-