Catalano.Math
Class Tools
- java.lang.Object
-
- Catalano.Math.Tools
-
public final class Tools extends java.lang.ObjectSet of mathematical tools.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleAngle(double x, double y)Gets the angle formed by the vector [x,y].static floatAngle(float x, float y)Gets the angle formed by the vector [x,y].static voidClamp(double[] values, double min, double max)Clamp values.static voidClamp(double[] values, DoubleRange range)Clamp values.static voidClamp(double[] values, java.util.List<DoubleRange> ranges)Clamp values.static doubleClamp(double x, double min, double max)Clamp values.static doubleClamp(double x, DoubleRange range)Clamp values.static floatClamp(float x, float min, float max)Clamp values.static floatClamp(float x, FloatRange range)Clamp values.static intClamp(int x, int min, int max)Clamp values.static intClamp(int x, IntRange range)Clamp values.static intDigitalRoot(int n)Return the digital root from a number.static intGreatestCommonDivisor(int a, int b)Gets the greatest common divisor between two integers.static doubleHypotenuse(double a, double b)Hypotenuse calculus without overflow/underflow.static booleanisNumeric(java.lang.String str)static booleanisPowerOf2(int x)Checks if the specified integer is power of 2.static doubleLog(double a, double b)Calculates the logarithm with base determined.static intLog2(int x)static intMod(int x, int m)Gets the proper modulus operation.static intNextPowerOf2(int x)Returns the next power of 2 after the input value x.static voidPermutate(int[] x)Generates a permutation of given array.static intPow2(int power)static intPreviousPowerOf2(int x)Returns the previous power of 2 after the input value x.static RandomRandom()static doubleRandomLaplacian()Generate a random number from laplacian distribution.static doubleRandomLaplacian(double mean, double std)Generate a random number from laplacian distribution.static doubleRandomNextDouble()Generate a random number in [0, 1).static doubleScale(double fromMin, double fromMax, double toMin, double toMax, double x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static doubleScale(DoubleRange from, DoubleRange to, double x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static doubleScale(DoubleRange from, DoubleRange to, int x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static floatScale(float fromMin, float fromMax, float toMin, float toMax, float x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static floatScale(FloatRange from, FloatRange to, int x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static intScale(IntRange from, IntRange to, int x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.static voidSetupGenerator(int seed)static doubleSinc(double x)Sinc function.static doubleSquare(double x)Gets the square of the number.static doubleSum(double[] data)Sum of the elements.static floatSum(float[] data)Sum of the elements.static intSum(int[] data)Sum of the elements.static doubleTruncatedPower(double value, double degree)Truncated power function.static int[]Unique(int[] values)Get unique values form the array.
-
-
-
Method Detail
-
Random
public static Random Random()
-
SetupGenerator
public static void SetupGenerator(int seed)
-
Square
public static double Square(double x)
Gets the square of the number.- Parameters:
x- Number.- Returns:
- x*x;
-
Sinc
public static double Sinc(double x)
Sinc function.- Parameters:
x- Value.- Returns:
- Sinc of the value.
-
Angle
public static float Angle(float x, float y)Gets the angle formed by the vector [x,y].- Parameters:
x- X axis coordinate.y- Y axis coordinate.- Returns:
- Angle formed by the vector.
-
Angle
public static double Angle(double x, double y)Gets the angle formed by the vector [x,y].- Parameters:
x- X axis coordinate.y- Y axis coordinate.- Returns:
- Angle formed by the vector.
-
Clamp
public static double Clamp(double x, DoubleRange range)Clamp values.- Parameters:
x- Value.range- Range.- Returns:
- Value.
-
Clamp
public static int Clamp(int x, IntRange range)Clamp values.- Parameters:
x- Value.range- Range.- Returns:
- Value.
-
Clamp
public static float Clamp(float x, FloatRange range)Clamp values.- Parameters:
x- Value.range- Range.- Returns:
- Value.
-
Clamp
public static double Clamp(double x, double min, double max)Clamp values.- Parameters:
x- Value.min- Minimum value.max- Maximum value.- Returns:
- Value.
-
Clamp
public static int Clamp(int x, int min, int max)Clamp values.- Parameters:
x- Value.min- Minimum value.max- Maximum value.- Returns:
- Value.
-
Clamp
public static float Clamp(float x, float min, float max)Clamp values.- Parameters:
x- Value.min- Minimum value.max- Maximum value.- Returns:
- Value.
-
Clamp
public static void Clamp(double[] values, java.util.List<DoubleRange> ranges)Clamp values.- Parameters:
values- Values.ranges- List of ranges.
-
Clamp
public static void Clamp(double[] values, DoubleRange range)Clamp values.- Parameters:
values- Values.range- Range.
-
Clamp
public static void Clamp(double[] values, double min, double max)Clamp values.- Parameters:
values- Values.min- Minimum value.max- Maximum value.
-
DigitalRoot
public static int DigitalRoot(int n)
Return the digital root from a number. Example: Number: 24365 Digital root: 2+4+3+6+5 = 20 = 2+0 = 2- Parameters:
n- Number.- Returns:
- Digital root.
-
GreatestCommonDivisor
public static int GreatestCommonDivisor(int a, int b)Gets the greatest common divisor between two integers.- Parameters:
a- First integer.b- Second integer.- Returns:
- Greatest common divisor.
-
isNumeric
public static boolean isNumeric(java.lang.String str)
-
isPowerOf2
public static boolean isPowerOf2(int x)
Checks if the specified integer is power of 2.- Parameters:
x- Integer number to check.- Returns:
- True: if the specified number is power of 2, otherwise returns false.
-
Mod
public static int Mod(int x, int m)Gets the proper modulus operation.- Parameters:
x- Integer.m- Modulo.- Returns:
- Modulus.
-
NextPowerOf2
public static int NextPowerOf2(int x)
Returns the next power of 2 after the input value x.- Parameters:
x- Input value x.- Returns:
- Returns the next power of 2 after the input value x.
-
Permutate
public static void Permutate(int[] x)
Generates a permutation of given array. This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
-
PreviousPowerOf2
public static int PreviousPowerOf2(int x)
Returns the previous power of 2 after the input value x.- Parameters:
x- value x.- Returns:
- Returns the previous power of 2 after the input value x.
-
RandomNextDouble
public static double RandomNextDouble()
Generate a random number in [0, 1). This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
-
RandomLaplacian
public static double RandomLaplacian()
Generate a random number from laplacian distribution.- Returns:
- Random number from laplacian distribution.
-
RandomLaplacian
public static double RandomLaplacian(double mean, double std)Generate a random number from laplacian distribution.- Parameters:
mean- Mean.std- Standard deviation.- Returns:
- Random number from laplacian distribution.
-
Scale
public static int Scale(IntRange from, IntRange to, int x)
Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
from- Scale from.to- Scale to.x- Value.- Returns:
- Result.
-
Scale
public static double Scale(DoubleRange from, DoubleRange to, int x)
Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
from- Scale from.to- Scale to.x- Value.- Returns:
- Result.
-
Scale
public static double Scale(DoubleRange from, DoubleRange to, double x)
Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
from- Scale from.to- Scale to.x- Value.- Returns:
- Result.
-
Scale
public static float Scale(FloatRange from, FloatRange to, int x)
Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
from- Scale from.to- Scale to.x- Value.- Returns:
- Result.
-
Scale
public static double Scale(double fromMin, double fromMax, double toMin, double toMax, double x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
fromMin- Scale min from.fromMax- Scale max from.toMin- Scale min to.toMax- Scale max to.x- Value.- Returns:
- Result.
-
Scale
public static float Scale(float fromMin, float fromMax, float toMin, float toMax, float x)Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.- Parameters:
fromMin- Scale min from.fromMax- Scale max from.toMin- Scale min to.toMax- Scale max to.x- Value.- Returns:
- Result.
-
Sum
public static double Sum(double[] data)
Sum of the elements.- Parameters:
data- Data.- Returns:
- Sum(data).
-
Sum
public static int Sum(int[] data)
Sum of the elements.- Parameters:
data- Data.- Returns:
- Sum(data).
-
Sum
public static float Sum(float[] data)
Sum of the elements.- Parameters:
data- Data.- Returns:
- Sum(data).
-
Log
public static double Log(double a, double b)Calculates the logarithm with base determined.- Parameters:
a- Value.b- Base.- Returns:
- Result.
-
TruncatedPower
public static double TruncatedPower(double value, double degree)Truncated power function.- Parameters:
value- Value.degree- Degree.- Returns:
- Result.
-
Unique
public static int[] Unique(int[] values)
Get unique values form the array.- Parameters:
values- Array of values.- Returns:
- Unique values.
-
Hypotenuse
public static double Hypotenuse(double a, double b)Hypotenuse calculus without overflow/underflow.- Parameters:
a- First value.b- Second value.- Returns:
- The hypotenuse Sqrt(a^2 + b^2).
-
Log2
public static int Log2(int x)
-
Pow2
public static int Pow2(int power)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG