public abstract class JaMath extends Object
Modifier and Type | Method and Description |
---|---|
static double |
avg(double... values) |
static float |
avg(float... values) |
static int |
avg(int... values) |
static long |
avg(long... values) |
static BigDecimal |
bigDec(double value)
Alias for
BigDecimal.valueOf(value) |
static BigDecimal |
bigDec(long value)
Alias for
BigDecimal.valueOf(value) |
static BigInteger |
bigInt(int value)
Alias for
BigInteger.valueOf(value) |
static BigInteger |
bigInt(long value)
Alias for
BigInteger.valueOf(value) |
static double |
cube(double d) |
static float |
cube(float f) |
static int |
cube(int i) |
static long |
cube(long l) |
static BigInteger |
factorial(BigInteger n) |
static int |
factorial(int n)
Use
factorial(long) for n in [0;20].Use factorial(BigInteger) for any n > 0. |
static long |
factorial(long n)
Use
factorial(BigInteger) for any n > 0. |
static boolean |
isPow2(int value)
Determines if the passed value is a power-of-2 value.
|
static void |
line(int x1,
int y1,
int x2,
int y2,
IntCoordinateManipulator manipulator) |
static Point[] |
linePoints(int x1,
int y1,
int x2,
int y2) |
static int[] |
linePointsInt1D(int x1,
int y1,
int x2,
int y2) |
static int[][] |
linePointsInt2D(int x1,
int y1,
int x2,
int y2) |
static int |
log2Bound(int n) |
static int |
log2pow2(int pow2Value) |
static double |
max(double... values) |
static float |
max(float... values) |
static int |
max(int... values) |
static long |
max(long... values) |
static double |
min(double... values) |
static float |
min(float... values) |
static int |
min(int... values) |
static long |
min(long... values) |
static double |
pow(double base,
int exponent) |
static float |
pow(float base,
int exponent) |
static int |
pow(int base,
int exponent)
This method is an int version of
Math.pow(double, double) ,
using only integer iteration for calculation. |
static int |
pow2Bound(int n) |
static Random |
random() |
static int |
random(int n) |
static _intRange |
range(int from,
int to)
Range.
|
static double |
round(double value,
int decimals)
Normalizes
value to the actual closest value for decimals decimals.This is useful if multiple subsequent calulations with double values accumulate rounding errors that drift the value away from the value it actually should (could) be. See the "candy" example in Joshua Bloch's "Effective Java": this method fixes the problem. |
static byte[] |
sequence(byte from,
byte to) |
static int[] |
sequence(int from,
int to)
Sequence.
|
static long[] |
sequence(long from,
long to) |
static short[] |
sequence(short from,
short to) |
static double |
square(double d) |
static float |
square(float f) |
static int |
square(int i) |
static long |
square(long l) |
static int |
stepCountDistance(int x1,
int y1,
int x2,
int y2)
Determines the amount of discrete steps from (x1,y1) to (x2,y2), where one step is a change of coordinates
in either straight or diagonal direction.
|
static double |
sum(double... values) |
static float |
sum(float... values) |
static int |
sum(int... values) |
static long |
sum(long... values) |
public static final int pow(int base, int exponent) throws IllegalArgumentException
Math.pow(double, double)
,
using only integer iteration for calculation.
As a rule of thumb:
It is faster for exponent
< 250 (significantly faster for exponents < 100)
and slower for exponent
>= 250 (significantly slower for exponents >= 500).
This may depend on the concrete system running the program, of course.
Note that exponent
may not be negative, otherwise an IllegalArgumentException
is
thrown.
(Why is there no Math.pow(int, int) in JDK ?)
base
- exponent
- my not be negativebase^exponent
IllegalArgumentException
- if exponent
is negativepublic static final int pow2Bound(int n)
public static final int log2Bound(int n)
public static final int log2pow2(int pow2Value)
public static final boolean isPow2(int value)
value
- value = 2^n
public static final float pow(float base, int exponent) throws IllegalArgumentException
IllegalArgumentException
public static final double pow(double base, int exponent) throws IllegalArgumentException
IllegalArgumentException
public static final float square(float f)
public static final long square(long l)
public static final int square(int i)
public static final double square(double d)
public static final float cube(float f)
public static final long cube(long l)
public static final int cube(int i)
public static final double cube(double d)
public static final double round(double value, int decimals)
value
to the actual closest value for decimals
decimals.
Note that decimals
may not be negative.
And note that while a value of 0 for decimals
will yield the correct result, it makes not much
sense to call this method for it in the first place.
value
- any double valuedecimals
- the number of decimals. May not be negative.value
public static _intRange range(int from, int to)
from
- the fromto
- the topublic static byte[] sequence(byte from, byte to)
public static short[] sequence(short from, short to)
public static int[] sequence(int from, int to)
from
- the fromto
- the topublic static long[] sequence(long from, long to) throws IllegalArgumentException
from
- to
- IllegalArgumentException
- if the range [from;to] is greater than Integer.MAX_VALUEpublic static final double max(double... values)
public static final float max(float... values)
public static final int max(int... values)
public static final long max(long... values)
public static final double min(double... values)
public static final float min(float... values)
public static final int min(int... values)
public static final long min(long... values)
public static final double sum(double... values)
public static final float sum(float... values)
public static final int sum(int... values)
public static final long sum(long... values)
public static final double avg(double... values)
public static final float avg(float... values)
public static final int avg(int... values)
public static final long avg(long... values)
public static final int stepCountDistance(int x1, int y1, int x2, int y2)
Examples:
(0,0) to (2,0) = 2 steps
(0,0) to (2,2) = 2 steps
(5,18) to (10,9) = 9 steps
x1
- y1
- x2
- y2
- public static final Point[] linePoints(int x1, int y1, int x2, int y2)
public static final int[] linePointsInt1D(int x1, int y1, int x2, int y2)
public static final int[][] linePointsInt2D(int x1, int y1, int x2, int y2)
public static final void line(int x1, int y1, int x2, int y2, IntCoordinateManipulator manipulator) throws InvalidCoordinateException
InvalidCoordinateException
public static final int factorial(int n) throws IllegalArgumentException
factorial(long)
for n in [0;20].factorial(BigInteger)
for any n > 0.n
- natural number in [0;12]IllegalArgumentException
- for n < 0 or n > 12public static final long factorial(long n) throws IllegalArgumentException
factorial(BigInteger)
for any n > 0.n
- natural number in [0;20]IllegalArgumentException
- for n < 0 or n > 20public static final BigInteger factorial(BigInteger n) throws IllegalArgumentException
n
- any natural number >= 0IllegalArgumentException
- for n < 0public static final BigInteger bigInt(int value)
BigInteger.valueOf(value)
value
- any valueBigInteger
representing value
public static final BigInteger bigInt(long value)
BigInteger.valueOf(value)
value
- any valueBigInteger
representing value
public static final BigDecimal bigDec(long value)
BigDecimal.valueOf(value)
value
- any valueBigDecimal
representing value
public static final BigDecimal bigDec(double value)
BigDecimal.valueOf(value)
value
- any valueBigDecimal
representing value
public static final Random random()
public static final int random(int n)
Copyright © 2003–2022 XDEV Software. All rights reserved.