public final class SqlMathUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
FULLBITS_31
Mask to convert an int to an unsigned int.
|
static int |
FULLBITS_32
Max unsigned integer.
|
static long |
FULLBITS_63
Mask to convert a long to an unsigned long.
|
static UnsignedInt128[] |
INVERSE_POWER_FIVES_INT128
1/5^x, scaled to 128bits (in other words, 2^128/5^x).
|
static UnsignedInt128[] |
INVERSE_POWER_TENS_INT128
1/10^x, scaled to 128bits, also word-shifted for better accuracy.
|
static int[] |
INVERSE_POWER_TENS_INT128_WORD_SHIFTS
number of words shifted up in each INVERSE_POWER_TENS_INT128.
|
static long |
LONG_MASK
Mask to convert signed integer to unsigned long.
|
static int |
MAX_POWER_FIVE_INT128
5^55 fits in 2^128.
|
static int |
MAX_POWER_FIVE_INT31
5^13 fits in 2^31.
|
static int |
MAX_POWER_FIVE_INT63
5^27 fits in 2^63.
|
static int |
MAX_POWER_TEN_INT128
10^38 fits in UnsignedInt128.
|
static int |
MAX_POWER_TEN_INT31
10^9 fits in 2^31.
|
static int |
NEGATIVE_INT_MASK
Mask to convert an int to a negative int.
|
static long |
NEGATIVE_LONG_MASK
Mask to convert a long to a negative long.
|
static UnsignedInt128[] |
POWER_FIVES_INT128
5^x.
|
static int[] |
POWER_FIVES_INT31
5^x.
|
static long[] |
POWER_FIVES_INT63
5^x.
|
static UnsignedInt128[] |
POWER_TENS_INT128
10^x.
|
static int[] |
POWER_TENS_INT31
10^x.
|
static UnsignedInt128[] |
ROUND_POWER_TENS_INT128
5 * 10^(x-1).
|
static int[] |
ROUND_POWER_TENS_INT31
5 * 10^(x-1).
|
Modifier and Type | Method and Description |
---|---|
static short |
bitLength(int v0,
int v1,
int v2,
int v3)
Returns the minimal number of bits to represent the words.
|
static short |
bitLengthInWord(int word)
Returns the minimal number of bits to represent the given integer value.
|
static long |
combineInts(int lo,
int hi) |
static int |
compareUnsignedInt(int x,
int y)
If we can assume JDK 1.8, this should use
java.lang.Integer.compareUnsigned(), which will be replaced with intrinsics
in JVM.
|
static int |
compareUnsignedLong(long x,
long y)
If we can assume JDK 1.8, this should use java.lang.Long.compareUnsigned(),
which will be replaced with intrinsics in JVM.
|
static int[] |
divideMultiPrecision(int[] dividend,
int[] divisor,
int[] quotient)
Multi-precision divide.
|
static long |
divideUnsignedLong(long dividend,
long divisor)
If we can assume JDK 1.8, this should use java.lang.Long.divideUnsigned(),
which will be replaced with intrinsics in JVM.
|
static int |
extractHiInt(long val) |
static int |
extractLowInt(long val) |
static long |
remainderUnsignedLong(long dividend,
long divisor)
If we can assume JDK 1.8, this should use
java.lang.Long.remainderUnsigned(), which will be replaced with intrinsics
in JVM.
|
static int |
setSignBitInt(int val,
boolean positive)
Turn on or off the highest bit of an int value.
|
static long |
setSignBitLong(long val,
boolean positive)
Turn on or off the highest bit of a long value.
|
public static final long NEGATIVE_LONG_MASK
public static final long FULLBITS_63
public static final int NEGATIVE_INT_MASK
public static final long LONG_MASK
public static final int FULLBITS_31
public static final int FULLBITS_32
public static final int MAX_POWER_FIVE_INT31
public static final int[] POWER_FIVES_INT31
public static final int MAX_POWER_FIVE_INT63
public static final long[] POWER_FIVES_INT63
public static final int MAX_POWER_FIVE_INT128
public static final UnsignedInt128[] POWER_FIVES_INT128
public static final UnsignedInt128[] INVERSE_POWER_FIVES_INT128
public static final int MAX_POWER_TEN_INT31
public static final int[] POWER_TENS_INT31
public static final int[] ROUND_POWER_TENS_INT31
public static final int MAX_POWER_TEN_INT128
public static final UnsignedInt128[] POWER_TENS_INT128
public static final UnsignedInt128[] ROUND_POWER_TENS_INT128
public static final UnsignedInt128[] INVERSE_POWER_TENS_INT128
public static final int[] INVERSE_POWER_TENS_INT128_WORD_SHIFTS
public static int setSignBitInt(int val, boolean positive)
val
- the value to modifypositive
- whether to turn off (positive) or on (negative).public static long setSignBitLong(long val, boolean positive)
val
- the value to modifypositive
- whether to turn off (positive) or on (negative).public static short bitLengthInWord(int word)
word
- int32 valuepublic static short bitLength(int v0, int v1, int v2, int v3)
v0
- v0v1
- v1v2
- v2v3
- v3public static int compareUnsignedInt(int x, int y)
x
- the first int
to comparey
- the second int
to compare0
if x == y
; a value less than 0
if x < y
as unsigned values; and a value greater than
0
if x > y
as unsigned valuespublic static int compareUnsignedLong(long x, long y)
x
- the first int
to comparey
- the second int
to compare0
if x == y
; a value less than 0
if x < y
as unsigned values; and a value greater than
0
if x > y
as unsigned valuespublic static long divideUnsignedLong(long dividend, long divisor)
dividend
- the value to be divideddivisor
- the value doing the dividingpublic static long remainderUnsignedLong(long dividend, long divisor)
dividend
- the value to be divideddivisor
- the value doing the dividingpublic static long combineInts(int lo, int hi)
lo
- low 32bithi
- high 32bitpublic static int extractHiInt(long val)
val
- long valuepublic static int extractLowInt(long val)
val
- long valuepublic static int[] divideMultiPrecision(int[] dividend, int[] divisor, int[] quotient)
dividend
- dividend. in.divisor
- divisor. in.quotient
- quotient. out.Copyright © 2017 The Apache Software Foundation. All rights reserved.