jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
Static Public Member Functions | |
static int | sign (final int x) |
Returns the value of the sign function. More... | |
static int | sign (final long x) |
See sign(int) . More... | |
static short | sign (final short x) |
See sign(int) . More... | |
static int | invert_sign (final int x) |
Safely inverts the sign of an integral number. More... | |
static long | invert_sign (final long x) |
See invert_sign(int) . More... | |
static short | invert_sign (final short x) |
See invert_sign(int) . More... | |
static int | abs (final int x) |
Returns the absolute value of an integral number. More... | |
static long | abs (final long x) |
See abs(int) . More... | |
static short | abs (final short x) |
See abs(int) . More... | |
static int | digits10 (final int x, final int x_sign, final boolean sign_is_digit) |
Returns the number of decimal digits of the given integral value number using std::log10<T>(). More... | |
static int | digits10 (final long x, final int x_sign, final boolean sign_is_digit) |
See digits10(int, int, boolean) More... | |
static int | digits10 (final int x, final boolean sign_is_digit) |
Returns the number of decimal digits of the given integral value number using std::log10<T>(). More... | |
static int | digits10 (final long x, final boolean sign_is_digit) |
See digits10(int, boolean) More... | |
Definition at line 26 of file IntMath.java.
|
static |
Returns the absolute value of an integral number.
Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
T | an integral number type |
x | the integral number |
Definition at line 105 of file IntMath.java.
|
static |
See abs(int)
.
Definition at line 112 of file IntMath.java.
|
static |
See abs(int)
.
Definition at line 118 of file IntMath.java.
|
static |
Returns the number of decimal digits of the given integral value number using std::log10<T>().
If sign_is_digit == true (default), treats a potential negative sign as a digit.
x < 0: 1 + (int) ( log10( -x ) ) + ( sign_is_digit ? 1 : 0 ) x = 0: 1 x > 0: 1 + (int) ( log10( x ) )
Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
T | an integral integer type |
x | the integral integer |
sign_is_digit | if true and value is negative, adds one to result for sign. Defaults to true. |
Definition at line 180 of file IntMath.java.
|
static |
Returns the number of decimal digits of the given integral value number using std::log10<T>().
If sign_is_digit == true (default), treats a potential negative sign as a digit.
x < 0: 1 + (int) ( log10( -x ) ) + ( sign_is_digit ? 1 : 0 ) x = 0: 1 x > 0: 1 + (int) ( log10( x ) )
Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.
Convenience method, reusing precomputed sign of value to avoid redundant computations.
x | the integral integer |
x_sign | the pre-determined sign of the given value x |
sign_is_digit | if true and value is negative, adds one to result for sign. Defaults to true. |
Definition at line 139 of file IntMath.java.
|
static |
|
static |
See digits10(int, int, boolean)
Definition at line 154 of file IntMath.java.
|
static |
Safely inverts the sign of an integral number.
Implementation takes special care to have T_MIN, i.e. std::numeric_limits<T>::min(), converted to T_MAX, i.e. std::numeric_limits<T>::max().
This is necessary since T_MAX < | -T_MIN |
and the result would not fit in the return type T otherwise.
Hence for the extreme minimum case:
jau::invert_sign<int32_t>(INT32_MIN) = | INT32_MIN | - 1 = INT32_MAX
Otherwise with x < 0:
jau::invert_sign<int32_t>(x) = | x | = -x
and x >= 0:
jau::invert_sign<int32_t>(x) = -x
x |
Definition at line 79 of file IntMath.java.
|
static |
See invert_sign(int)
.
Definition at line 86 of file IntMath.java.
|
static |
See invert_sign(int)
.
Definition at line 92 of file IntMath.java.
|
static |
Returns the value of the sign function.
-1 for x < 0 0 for x = 0 1 for x > 0
Implementation is type safe.
x | the integral number |
Definition at line 39 of file IntMath.java.
|
static |
See sign(int)
.
Definition at line 46 of file IntMath.java.
|
static |
See sign(int)
.
Definition at line 52 of file IntMath.java.