Package org.apache.lucene.util
Class SloppyMath
- java.lang.Object
-
- org.apache.lucene.util.SloppyMath
-
public class SloppyMath extends java.lang.ObjectMath functions that trade off accuracy for speed.
-
-
Field Summary
Fields Modifier and Type Field Description private static doubleASIN_DELTAprivate static doubleASIN_INDEXERprivate static doubleASIN_MAX_VALUE_FOR_TABSprivate static doubleASIN_PIO2_HIprivate static doubleASIN_PIO2_LOprivate static doubleASIN_PS0private static doubleASIN_PS1private static doubleASIN_PS2private static doubleASIN_PS3private static doubleASIN_PS4private static doubleASIN_PS5private static doubleASIN_QS1private static doubleASIN_QS2private static doubleASIN_QS3private static doubleASIN_QS4private static intASIN_TABS_SIZEprivate static double[]asinDer1DivF1Tabprivate static double[]asinDer2DivF2Tabprivate static double[]asinDer3DivF3Tabprivate static double[]asinDer4DivF4Tabprivate static double[]asinTabprivate static double[]cosTabprivate static doubleONE_DIV_F2private static doubleONE_DIV_F3private static doubleONE_DIV_F4private static doublePIO2_HIprivate static doublePIO2_LOprivate static doubleSIN_COS_DELTA_HIprivate static doubleSIN_COS_DELTA_LOprivate static doubleSIN_COS_INDEXER(package private) static doubleSIN_COS_MAX_VALUE_FOR_INT_MODULOprivate static intSIN_COS_TABS_SIZEprivate static double[]sinTabstatic doubleTO_DEGREESprivate static doubleTO_KILOMETERSprivate static doubleTO_METERSstatic doubleTO_RADIANSprivate static doubleTWOPI_HIprivate static doubleTWOPI_LO
-
Constructor Summary
Constructors Constructor Description SloppyMath()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static doubleasin(double a)Returns the arc sine of a value.static doublecos(double a)Returns the trigonometric cosine of an angle.static doublehaversinKilometers(double lat1, double lon1, double lat2, double lon2)Deprecated.Useinsteadstatic doublehaversinMeters(double sortKey)Returns the Haversine distance in meters between two points given the previous result fromhaversinSortKey(double, double, double, double)static doublehaversinMeters(double lat1, double lon1, double lat2, double lon2)Returns the Haversine distance in meters between two points specified in decimal degrees (latitude/longitude).static doublehaversinSortKey(double lat1, double lon1, double lat2, double lon2)Returns a sort key for distance.static doubletoDegrees(double radians)Deprecated.UseMath.toDegrees(double)on Java 9+.static doubletoRadians(double degrees)Deprecated.UseMath.toRadians(double)on Java 9+.
-
-
-
Field Detail
-
TO_RADIANS
public static final double TO_RADIANS
- See Also:
- Constant Field Values
-
TO_DEGREES
public static final double TO_DEGREES
- See Also:
- Constant Field Values
-
TO_METERS
private static final double TO_METERS
- See Also:
- Constant Field Values
-
TO_KILOMETERS
private static final double TO_KILOMETERS
- See Also:
- Constant Field Values
-
ONE_DIV_F2
private static final double ONE_DIV_F2
- See Also:
- Constant Field Values
-
ONE_DIV_F3
private static final double ONE_DIV_F3
- See Also:
- Constant Field Values
-
ONE_DIV_F4
private static final double ONE_DIV_F4
- See Also:
- Constant Field Values
-
PIO2_HI
private static final double PIO2_HI
-
PIO2_LO
private static final double PIO2_LO
-
TWOPI_HI
private static final double TWOPI_HI
-
TWOPI_LO
private static final double TWOPI_LO
-
SIN_COS_TABS_SIZE
private static final int SIN_COS_TABS_SIZE
- See Also:
- Constant Field Values
-
SIN_COS_DELTA_HI
private static final double SIN_COS_DELTA_HI
-
SIN_COS_DELTA_LO
private static final double SIN_COS_DELTA_LO
-
SIN_COS_INDEXER
private static final double SIN_COS_INDEXER
-
sinTab
private static final double[] sinTab
-
cosTab
private static final double[] cosTab
-
SIN_COS_MAX_VALUE_FOR_INT_MODULO
static final double SIN_COS_MAX_VALUE_FOR_INT_MODULO
-
ASIN_MAX_VALUE_FOR_TABS
private static final double ASIN_MAX_VALUE_FOR_TABS
-
ASIN_TABS_SIZE
private static final int ASIN_TABS_SIZE
- See Also:
- Constant Field Values
-
ASIN_DELTA
private static final double ASIN_DELTA
-
ASIN_INDEXER
private static final double ASIN_INDEXER
-
asinTab
private static final double[] asinTab
-
asinDer1DivF1Tab
private static final double[] asinDer1DivF1Tab
-
asinDer2DivF2Tab
private static final double[] asinDer2DivF2Tab
-
asinDer3DivF3Tab
private static final double[] asinDer3DivF3Tab
-
asinDer4DivF4Tab
private static final double[] asinDer4DivF4Tab
-
ASIN_PIO2_HI
private static final double ASIN_PIO2_HI
-
ASIN_PIO2_LO
private static final double ASIN_PIO2_LO
-
ASIN_PS0
private static final double ASIN_PS0
-
ASIN_PS1
private static final double ASIN_PS1
-
ASIN_PS2
private static final double ASIN_PS2
-
ASIN_PS3
private static final double ASIN_PS3
-
ASIN_PS4
private static final double ASIN_PS4
-
ASIN_PS5
private static final double ASIN_PS5
-
ASIN_QS1
private static final double ASIN_QS1
-
ASIN_QS2
private static final double ASIN_QS2
-
ASIN_QS3
private static final double ASIN_QS3
-
ASIN_QS4
private static final double ASIN_QS4
-
-
Method Detail
-
haversinMeters
public static double haversinMeters(double lat1, double lon1, double lat2, double lon2)Returns the Haversine distance in meters between two points specified in decimal degrees (latitude/longitude). This works correctly even if the dateline is between the two points.Error is at most 4E-1 (40cm) from the actual haversine distance, but is typically much smaller for reasonable distances: around 1E-5 (0.01mm) for distances less than 1000km.
- Parameters:
lat1- Latitude of the first point.lon1- Longitude of the first point.lat2- Latitude of the second point.lon2- Longitude of the second point.- Returns:
- distance in meters.
-
haversinMeters
public static double haversinMeters(double sortKey)
Returns the Haversine distance in meters between two points given the previous result fromhaversinSortKey(double, double, double, double)- Returns:
- distance in meters.
-
haversinKilometers
@Deprecated public static double haversinKilometers(double lat1, double lon1, double lat2, double lon2)Deprecated.UseinsteadReturns the Haversine distance in kilometers between two points specified in decimal degrees (latitude/longitude). This works correctly even if the dateline is between the two points.- Parameters:
lat1- Latitude of the first point.lon1- Longitude of the first point.lat2- Latitude of the second point.lon2- Longitude of the second point.- Returns:
- distance in kilometers.
-
haversinSortKey
public static double haversinSortKey(double lat1, double lon1, double lat2, double lon2)Returns a sort key for distance. This is less expensive to compute thanhaversinMeters(double, double, double, double), but it always compares the same. This can be converted into an actual distance withhaversinMeters(double), which effectively does the second half of the computation.
-
cos
public static double cos(double a)
Returns the trigonometric cosine of an angle.Error is around 1E-15.
Special cases:
- If the argument is
NaNor an infinity, then the result isNaN.
- Parameters:
a- an angle, in radians.- Returns:
- the cosine of the argument.
- See Also:
Math.cos(double)
- If the argument is
-
asin
public static double asin(double a)
Returns the arc sine of a value.The returned angle is in the range -pi/2 through pi/2. Error is around 1E-7.
Special cases:
- If the argument is
NaNor its absolute value is greater than 1, then the result isNaN.
- Parameters:
a- the value whose arc sine is to be returned.- Returns:
- arc sine of the argument
- See Also:
Math.asin(double)
- If the argument is
-
toDegrees
@Deprecated public static double toDegrees(double radians)
Deprecated.UseMath.toDegrees(double)on Java 9+.Convert to degrees.- Parameters:
radians- radians to convert to degrees- Returns:
- degrees
-
toRadians
@Deprecated public static double toRadians(double degrees)
Deprecated.UseMath.toRadians(double)on Java 9+.Convert to radians.- Parameters:
degrees- degrees to convert to radians- Returns:
- radians
-
-