public class

MathUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.math.MathUtil

Class Overview

Set of common operations on Number that are not in Math.

Summary

Public Constructors
MathUtil()
Public Methods
static double avg(byte[] array)
static double avg(float[] array)
static double avg(short[] array)
static double avg(int[] array)
static double avg(long[] array)
static double avg(Collection<? extends Number> collection)
static double avg(double[] array)
static double avg(char[] array)
static boolean betweenExclusive(long value, long min, long max)
Check that a value is between two bounds (exclusive)
static boolean betweenInclusive(long value, long min, long max)
Check that a value is between two bounds (inclusive)
static int minPositive(int... values)
Get the min of the values which is > 0.
static int moduloPositive(int a, int b)
Calculate the positive remainder of two integers.
static int pow(int a, int b)
Integer pow
static long signExtend(long value, int bitsize)
static long signExtend(long value, int bitsize, int extendTo)
static long unmaskedArithShiftRight(long v, int cnt)
static long unmaskedShiftLeft(long v, int cnt)
static long unmaskedShiftRight(long v, int cnt)
static long zeroExtend(long value, int bitsize, int extendTo)
static long zeroExtend(long value, int bitsize)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MathUtil ()

Public Methods

public static double avg (byte[] array)

public static double avg (float[] array)

public static double avg (short[] array)

public static double avg (int[] array)

public static double avg (long[] array)

public static double avg (Collection<? extends Number> collection)

public static double avg (double[] array)

public static double avg (char[] array)

public static boolean betweenExclusive (long value, long min, long max)

Check that a value is between two bounds (exclusive)

Parameters
value value
min min bound
max max bound
Returns
  • true if when value is in range ]min, max[

public static boolean betweenInclusive (long value, long min, long max)

Check that a value is between two bounds (inclusive)

Parameters
value value
min min bound
max max bound
Returns
  • true if when value is in range [min, max]

public static int minPositive (int... values)

Get the min of the values which is > 0. (for example when looking for min indexOf)

public static int moduloPositive (int a, int b)

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.

Parameters
a any integer
b a strictly positive integer
Returns
  • positive remainder

public static int pow (int a, int b)

Integer pow

public static long signExtend (long value, int bitsize)

public static long signExtend (long value, int bitsize, int extendTo)

public static long unmaskedArithShiftRight (long v, int cnt)

public static long unmaskedShiftLeft (long v, int cnt)

public static long unmaskedShiftRight (long v, int cnt)

public static long zeroExtend (long value, int bitsize, int extendTo)

public static long zeroExtend (long value, int bitsize)