Package ffx.numerics.math
Class ScalarMath
java.lang.Object
ffx.numerics.math.ScalarMath
The ScalarMath class is a simple math library that operates on single variables
- Since:
- 1.0
- Author:
- Jacob M. Litman, Michael J. Schnieders
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
b2u
(double b) b2ustatic long
binomial
(long n, long k) binomialstatic long
doubleFactorial
(long n) Returns n!!static long
factorial
(long n) Returns n!static double
fermiFunction
(double x) Compute 1.0 / (1.0 + exp(x)).static double
mirrorDegrees
(double angle) Reflect proposed angles to be within 0 and 180 degrees.static double
mirrorRadians
(double angle) Reflect proposed angles to be within 0 and 180 degrees.static double
mod
(double a, double b) This is an atypical mod function used by crystallography methods.static int
mod
(int a, int b) This is an atypical mod function used by crystallography methods.static double
modToRange
(double value, double lb, double ub) Atypical mod function used to move a value into the range lb <= value < ub, assuming the domain is periodic with a period of (ub - lb).static double
quadForm
(double[] v, double[][] mat) quadFormstatic double
u2b
(double u) u2b
-
Method Details
-
b2u
public static double b2u(double b) b2u- Parameters:
b
- a double.- Returns:
- a double.
-
binomial
public static long binomial(long n, long k) binomial- Parameters:
n
- a long.k
- a long.- Returns:
- Returns the binomial of (n,k).
-
doubleFactorial
public static long doubleFactorial(long n) Returns n!! Precondition: n .GE. -1 Returning 1 for -1 input is analogous to Maple behavior.- Parameters:
n
- long.- Returns:
- Returns the n!!.
-
factorial
public static long factorial(long n) Returns n!
Precondition: n .GE. 0 and n .LE. 20
Max long = 9223372036854775807
20! = 2432902008176640000 is ok.
21! returns an overflow: -4249290049419214848- Parameters:
n
- long.- Returns:
- Returns n!.
-
fermiFunction
public static double fermiFunction(double x) Compute 1.0 / (1.0 + exp(x)).- Parameters:
x
- Input.- Returns:
- Returns 1.0 / (1.0 + exp(x)).
-
mod
public static double mod(double a, double b) This is an atypical mod function used by crystallography methods.mod
- Parameters:
a
- Value to mod.b
- Value to mod by.- Returns:
- Positive a % b.
-
mod
public static int mod(int a, int b) This is an atypical mod function used by crystallography methods.- Parameters:
a
- an int.b
- an int.- Returns:
- an int.
-
modToRange
public static double modToRange(double value, double lb, double ub) Atypical mod function used to move a value into the range lb <= value < ub, assuming the domain is periodic with a period of (ub - lb).- Parameters:
value
- Value to move between bounds.lb
- Lower bound.ub
- Upper bound.- Returns:
- Returns periodic copy of value, in the range lb <= value < ub.
-
u2b
public static double u2b(double u) u2b- Parameters:
u
- a double.- Returns:
- a double.
-
quadForm
public static double quadForm(double[] v, double[][] mat) quadForm- Parameters:
v
- an array of double.mat
- an array of double.- Returns:
- a double.
-
mirrorRadians
public static double mirrorRadians(double angle) Reflect proposed angles to be within 0 and 180 degrees.- Parameters:
angle
- Proposed angle in radians.- Returns:
- value of mirrored angle in radians.
-
mirrorDegrees
public static double mirrorDegrees(double angle) Reflect proposed angles to be within 0 and 180 degrees.- Parameters:
angle
- Proposed angle in radians.- Returns:
- value of mirrored angle in radians.
-