jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Static Public Member Functions | List of all members
org.jau.util.IntMath Class Reference
Collaboration diagram for org.jau.util.IntMath:

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...
 

Detailed Description

Definition at line 26 of file IntMath.java.

Member Function Documentation

◆ abs() [1/3]

static int org.jau.util.IntMath.abs ( final int  x)
static

Returns the absolute value of an integral number.

Implementation uses jau::invert_sign() to have a safe absolute value conversion, if required.

Template Parameters
Tan integral number type
Parameters
xthe integral number
Returns
function result

Definition at line 105 of file IntMath.java.

Here is the call graph for this function:

◆ abs() [2/3]

static long org.jau.util.IntMath.abs ( final long  x)
static

See abs(int).

Definition at line 112 of file IntMath.java.

Here is the call graph for this function:

◆ abs() [3/3]

static short org.jau.util.IntMath.abs ( final short  x)
static

See abs(int).

Definition at line 118 of file IntMath.java.

Here is the call graph for this function:

◆ digits10() [1/4]

static int org.jau.util.IntMath.digits10 ( final int  x,
final boolean  sign_is_digit 
)
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.

Template Parameters
Tan integral integer type
Parameters
xthe integral integer
sign_is_digitif true and value is negative, adds one to result for sign. Defaults to true.
Returns
digit count

Definition at line 180 of file IntMath.java.

Here is the call graph for this function:

◆ digits10() [2/4]

static int org.jau.util.IntMath.digits10 ( final int  x,
final int  x_sign,
final boolean  sign_is_digit 
)
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.

Parameters
xthe integral integer
x_signthe pre-determined sign of the given value x
sign_is_digitif true and value is negative, adds one to result for sign. Defaults to true.
Returns
digit count

Definition at line 139 of file IntMath.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ digits10() [3/4]

static int org.jau.util.IntMath.digits10 ( final long  x,
final boolean  sign_is_digit 
)
static

See digits10(int, boolean)

Definition at line 187 of file IntMath.java.

Here is the call graph for this function:

◆ digits10() [4/4]

static int org.jau.util.IntMath.digits10 ( final long  x,
final int  x_sign,
final boolean  sign_is_digit 
)
static

See digits10(int, int, boolean)

Definition at line 154 of file IntMath.java.

Here is the call graph for this function:

◆ invert_sign() [1/3]

static int org.jau.util.IntMath.invert_sign ( final int  x)
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
Parameters
x
Returns

Definition at line 79 of file IntMath.java.

Here is the caller graph for this function:

◆ invert_sign() [2/3]

static long org.jau.util.IntMath.invert_sign ( final long  x)
static

See invert_sign(int).

Definition at line 86 of file IntMath.java.

◆ invert_sign() [3/3]

static short org.jau.util.IntMath.invert_sign ( final short  x)
static

See invert_sign(int).

Definition at line 92 of file IntMath.java.

◆ sign() [1/3]

static int org.jau.util.IntMath.sign ( final int  x)
static

Returns the value of the sign function.

-1 for x < 0
 0 for x = 0
 1 for x > 0

Implementation is type safe.

Parameters
xthe integral number
Returns
function result

Definition at line 39 of file IntMath.java.

Here is the caller graph for this function:

◆ sign() [2/3]

static int org.jau.util.IntMath.sign ( final long  x)
static

See sign(int).

Definition at line 46 of file IntMath.java.

◆ sign() [3/3]

static short org.jau.util.IntMath.sign ( final short  x)
static

See sign(int).

Definition at line 52 of file IntMath.java.


The documentation for this class was generated from the following file: