Class DoubleBits
java.lang.Object
org.locationtech.jts.index.quadtree.DoubleBits
DoubleBits manipulates Double numbers
by using bit manipulation and bit-field extraction.
For some operations (such as determining the exponent)
this is more accurate than using mathematical operations
(which suffer from round-off error).
The algorithms and constants in this class apply only to IEEE-754 double-precision floating point format.
- Version:
- 1.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
private double
private long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Determines the exponent for the numberstatic int
exponent
(double d) int
getBit
(int i) double
int
Determines the exponent for the numberstatic double
maximumCommonMantissa
(double d1, double d2) int
This computes the number of common most-significant bits in the mantissa.static double
powerOf2
(int exp) static String
toBinaryString
(double d) toString()
A representation of the Double bits formatted for easy readabilitystatic double
truncateToPowerOfTwo
(double d) void
zeroLowerBits
(int nBits)
-
Field Details
-
EXPONENT_BIAS
public static final int EXPONENT_BIAS- See Also:
-
x
private double x -
xBits
private long xBits
-
-
Constructor Details
-
DoubleBits
public DoubleBits(double x)
-
-
Method Details
-
powerOf2
public static double powerOf2(int exp) -
exponent
public static int exponent(double d) -
truncateToPowerOfTwo
public static double truncateToPowerOfTwo(double d) -
toBinaryString
-
maximumCommonMantissa
public static double maximumCommonMantissa(double d1, double d2) -
getDouble
public double getDouble() -
biasedExponent
public int biasedExponent()Determines the exponent for the number -
getExponent
public int getExponent()Determines the exponent for the number -
zeroLowerBits
public void zeroLowerBits(int nBits) -
getBit
public int getBit(int i) -
numCommonMantissaBits
This computes the number of common most-significant bits in the mantissa. It does not count the hidden bit, which is always 1. It does not determine whether the numbers have the same exponent - if they do not, the value computed by this function is meaningless.- Parameters:
db
-- Returns:
- the number of common most-significant mantissa bits
-
toString
A representation of the Double bits formatted for easy readability
-