# Class: com.pnfsoftware.jeb.util.math.MathUtil

Set of common operations on [Number](Number) that are not in [Math](Math).

## Static Method: almostEquals
- parameter: `a`, type: `double`
- parameter: `b`, type: `double`
- return type: `boolean`

Description: Check for almost equality: tolerate a 1e\-7 gap to make up for numerical errors inherent to IEEE754 calculations.
parameter: a: first value
parameter: b: second value
return: true if `|a-b| <= 1e-7`

## Static Method: almostEquals
- parameter: `a`, type: `double`
- parameter: `b`, type: `double`
- parameter: `epsilon`, type: `double`
- return type: `boolean`

Description: Check for almost equality: tolerate an epsilon gap to make up for numerical errors inherent to IEEE754 calculations.
parameter: a: first value
parameter: b: second value
parameter: epsilon: a positive number
return: true if `|a-b| <= epsilon`

## Static Method: avg
- parameter: `collection`, type: `java.util.Collection<? extends java.lang.Number>`
- return type: `double`

Description: Compute the arithmetic mean of a collection of numbers.
parameter: collection: non\-empty collection
return: the average value
throws: if the collection is empty

## Static Method: avg
- parameter: `array`, type: `byte[]`
- return type: `double`

Description: Compute the arithmetic mean of a byte array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `char[]`
- return type: `double`

Description: Compute the arithmetic mean of a char array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `short[]`
- return type: `double`

Description: Compute the arithmetic mean of a short array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `int[]`
- return type: `double`

Description: Compute the arithmetic mean of an int array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `long[]`
- return type: `double`

Description: Compute the arithmetic mean of a long array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `float[]`
- return type: `double`

Description: Compute the arithmetic mean of a float array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: avg
- parameter: `array`, type: `double[]`
- return type: `double`

Description: Compute the arithmetic mean of a double array.
parameter: array: non\-empty array
return: the average value
throws: if the array is empty

## Static Method: betweenExclusive
- parameter: `value`, type: `long`
- parameter: `min`, type: `long`
- parameter: `max`, type: `long`
- return type: `boolean`

Description: Check that a value is between two bounds \(exclusive\).
parameter: value: value
parameter: min: min bound
parameter: max: max bound
return: true if when value is in range \]min, max\[

## Static Method: betweenInclusive
- parameter: `value`, type: `long`
- parameter: `min`, type: `long`
- parameter: `max`, type: `long`
- return type: `boolean`

Description: Check that a value is between two bounds \(inclusive\).
parameter: value: value
parameter: min: min bound
parameter: max: max bound
return: true if when value is in range \[min, max\]

## Static Method: bitcount
- parameter: `value`, type: `int`
- return type: `int`

Description: Count the number of set bits in an integer.
parameter: value: value to inspect
return: the number of one bits

## Static Method: bitcount
- parameter: `value`, type: `long`
- return type: `int`

Description: Count the number of set bits in a long integer.
parameter: value: value to inspect
return: the number of one bits

## Static Method: isPowerOfTwo
- parameter: `n`, type: `int`
- return type: `boolean`

Description: Determine whether a strictly positive integer is a power of 2.
parameter: n: a positive integer
return: true if `n` is a power of two

## Static Method: isPowerOfTwo
- parameter: `n`, type: `long`
- return type: `boolean`

Description: Determine whether a strictly positive integer is a power of 2.
parameter: n: a positive integer
return: true if `n` is a power of two

## Static Method: log2
- parameter: `n`, type: `int`
- return type: `int`

Description: Get the truncated base2 log of the input.
parameter: n: must be strictly positive
return: the truncated base\-2 logarithm of `n`

## Static Method: log2
- parameter: `n`, type: `long`
- return type: `int`

Description: Get the truncated base2 log of the input.
parameter: n: must be strictly positive
return: the truncated base\-2 logarithm of `n`

## Static Method: makeInverseMask
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Create a 64\-bit inverse mask. Safe replacement for `~((ONE << BITSIZE) - ONE)` constructs.
parameter: bitsize: bitsize \[0, 64\]
return: the inverse mask
throws: if the bitsize is out of range

## Static Method: makeMask
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Create a 64\-bit mask. Safe replacement for `(ONE << BITSIZE) - ONE` constructs.
parameter: bitsize: bitsize \[0, 64\]
return: the mask
throws: if the bitsize is out of range

## Static Method: makeOverflow
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Create a 64\-bit overflow. Safe replacement for `(ONE << BITSIZE)` constructs.
parameter: bitsize: bitsize \[0, 64\]
return: the overflow
throws: if the bitsize is out of range

## Static Method: moduloPositive
- parameter: `a`, type: `int`
- parameter: `b`, type: `int`
- return type: `int`

Description: Calculate the positive remainder of two integers. 

 Note: Java standard modulo operators specifies that the remainder will have the sign of the numerator. This method provides an alternate way to calculate the remainder, often\-time more useful, by making sure that it remains positive.
parameter: a: any integer
parameter: b: a positive integer
return: positive remainder
throws: if b is zero

## Static Method: msb
- parameter: `value`, type: `long`
- parameter: `bitsize`, type: `int`
- return type: `int`

Description: Retrieve the most significant bit of a fixed\-width value.
parameter: value: value to inspect
parameter: bitsize: must be in \[1, 64\]
return: 0 or 1

## Static Method: pow
- parameter: `a`, type: `int`
- parameter: `b`, type: `int`
- return type: `int`

Description: Integer exponentiation.
parameter: a: base
parameter: b: exponent
return: a\*\*b \(may have overflowed\)

## Static Method: pow
- parameter: `a`, type: `long`
- parameter: `b`, type: `long`
- return type: `long`

Description: Long int exponentiation.
parameter: a: base
parameter: b: exponent
return: a\*\*b \(may have overflowed\)

## Static Method: signExtend
- parameter: `value`, type: `long`
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Sign\-extend a value to 64 bits.
parameter: value: value to extend
parameter: bitsize: must be in \[1, 64\]
return: the sign\-extended 64\-bit value

## Static Method: signExtend32
- parameter: `value`, type: `long`
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Sign\-extend a value to 32 bits.
parameter: value: value to extend
parameter: bitsize: must be in \[1, 32\]
return: the sign\-extended 32\-bit value stored in a long

## Static Method: signExtend32
- parameter: `value`, type: `int`
- parameter: `bitsize`, type: `int`
- return type: `int`

Description: Sign\-extend a value to 32 bits.
parameter: value: value to extend
parameter: bitsize: must be in \[1, 32\]
return: the sign\-extended 32\-bit value

## Static Method: unmaskedArithShiftRight
- parameter: `v`, type: `long`
- parameter: `cnt`, type: `int`
- return type: `long`

Description: Arithmetically right\-shift a long value without Java's 6\-bit shift\-count masking.
parameter: v: value to shift
parameter: cnt: shift count
return: sign\-filled result if `cnt >= 64`, otherwise `v >> cnt`

## Static Method: unmaskedShiftLeft
- parameter: `v`, type: `long`
- parameter: `cnt`, type: `int`
- return type: `long`

Description: Left\-shift a long value without Java's 6\-bit shift\-count masking.
parameter: v: value to shift
parameter: cnt: shift count
return: zero if `cnt >= 64`, otherwise `v << cnt`

## Static Method: unmaskedShiftRight
- parameter: `v`, type: `long`
- parameter: `cnt`, type: `int`
- return type: `long`

Description: Logically right\-shift a long value without Java's 6\-bit shift\-count masking.
parameter: v: value to shift
parameter: cnt: shift count
return: zero if `cnt >= 64`, otherwise `v >>> cnt`

## Static Method: zeroExtend
- parameter: `value`, type: `long`
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Zero\-extend a value to 64 bits.
parameter: value: value to extend
parameter: bitsize: must be in \[1, 64\]
return: the zero\-extended 64\-bit value

## Static Method: zeroExtend32
- parameter: `value`, type: `long`
- parameter: `bitsize`, type: `int`
- return type: `long`

Description: Zero\-extend a value to 32 bits.
parameter: value: value to extend
parameter: bitsize: must be in \[1, 32\]
return: the zero\-extended 32\-bit value stored in a long

