Package io.higson.runtime.rhino
Class RhinoMath
java.lang.Object
io.higson.runtime.rhino.RhinoMath
Utility class providing mathematical functions which can be used within Higson functions
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleabs(double a) Returns absolute value of the argument using standard Java functionMath.abs(double).static floatabs(float a) Returns absolute value of the argument using standard Java functionMath.abs(float).static intabs(int a) Returns absolute value of the argument using standard Java functionMath.abs(int).static longabs(long a) Returns absolute value of the argument using standard Java functionMath.abs(long).static doubleacos(double a) Calculates the arc cosine of an argument, using standard Java functionMath.acos(double).static doubleasin(double a) Calculates the arc sine of an argument using standard Java functionMath.asin(double).static doubleatan(double a) Calculates the arc tangent of an argument, using standard Java functionMath.atan(double).static doublecbrt(double a) Calculates the cube root using standard Java functionStrictMath.cbrt(double).static doubleceil(double a) Returns the smallest rounded to whole number value which is greater than or equal to the argument, using standard Java functionMath.ceil(double).static doublecos(double a) Calculates trigonometric cosine of an angle using standard Java functionMath.cos(double).static doublecosh(double x) Calculates the hyperbolic cosine, using standard Java functionMath.cosh(double).static doubleexp(double a) Calculates Euler's numbereraised to the given power using standard Java functionMath.exp(double).static doublefloor(double a) Returns the largest rounded to whole number value which is less than or equal to the argument, using standard Java functionMath.floor(double).static doublelog(double a) Calculates the natural logarithm using standard Java functionMath.log(double).static doublelog(double a, double b) Calculates logarithm ofbwith basea.static doublelog10(double a) Calculates the base 10 logarithm using standard Java functionMath.log10(double).static doublemax(double a, double b) Returns the greater of two values found using standard Java functionMath.max(double, double).static floatmax(float a, float b) Returns the greater of two values found using standard Java functionMath.max(float, float).static intmax(int a, int b) Returns the greater of two values found using standard Java functionMath.max(int, int).static longmax(long a, long b) Returns the greater of two values found using standard Java functionMath.max(long, long).static doublemin(double a, double b) Returns the smaller of two values found using standard Java functionMath.min(double, double).static floatmin(float a, float b) Returns the smaller of two values found using standard Java functionMath.min(float, float).static intmin(int a, int b) Returns the smaller of two values found using standard Java functionMath.min(int, int).static longmin(long a, long b) Returns the smaller of two values found using standard Java functionMath.min(long, long).static doublepow(double a, double b) Returns the value of the first argument raised to the power of the second argument, calculated using standard Java functionMath.pow(double, double).static doublerandom()Returns a pseudo-random number greater than or equal to0.0and less than1.0, using standard Java functionMath.random()static longround(double a) Returns the closestlongto the argument, with ties rounding to positive infinity, using standard Java functionMath.round(double).static doubleround(double a, int scale) Rounds the number to specified decimal places.static intround(float a) Returns the closestintto the argument, calculated using standard Java functionMath.round(float).static doublesignum(double d) Returns the signum function of the argument, determined using standard Java functionMath.signum(double).static floatsignum(float f) Returns the signum function of the argument, determined using standard Java functionMath.signum(float).static doublesin(double a) Calculates trigonometric sine of an angle using standard Java functionMath.sin(double).static doublesinh(double x) Calculates the hyperbolic sine, using standard Java functionMath.sinh(double).static doublesqrt(double a) Calculates the positive square root using standard Java functionMath.sqrt(double).static doubletan(double a) Calculates trigonometric tangent of an angle using standard Java functionMath.tan(double).static doubletoDegrees(double angrad) Converts an angle measured in radians to angle measured in degrees, using standard Java functionMath.toDegrees(double).static doubletoRadians(double angdeg) Converts an angle measured in degrees to angle measured in radians, using standard Java functionMath.toRadians(double).static doubletrunc(double a, int scale) Rounds the number to specified decimal places.
-
Field Details
-
INSTANCE
-
E
public static final double EEuler's numbere=2.718..., base of natural logarithm- See Also:
-
PI
public static final double PINumber π= 3.14...- See Also:
-
-
Method Details
-
sin
public static double sin(double a) Calculates trigonometric sine of an angle using standard Java functionMath.sin(double).- Parameters:
a- angle in radians- Returns:
- sine of
a.
-
cos
public static double cos(double a) Calculates trigonometric cosine of an angle using standard Java functionMath.cos(double).- Parameters:
a- angle in radians- Returns:
- cosine of
a.
-
tan
public static double tan(double a) Calculates trigonometric tangent of an angle using standard Java functionMath.tan(double).- Parameters:
a- angle in radians- Returns:
- tangent of
a.
-
asin
public static double asin(double a) Calculates the arc sine of an argument using standard Java functionMath.asin(double).- Parameters:
a- value whose arc sine is to be calculated- Returns:
- arc sine of
a. If the absolute value ofais greater than 1, the result isNaN.
-
acos
public static double acos(double a) Calculates the arc cosine of an argument, using standard Java functionMath.acos(double).- Parameters:
a- value whose arc cosine is to be calculated- Returns:
- arc cosine of
a. If the absolute value ofais greater than 1, the result isNaN.
-
atan
public static double atan(double a) Calculates the arc tangent of an argument, using standard Java functionMath.atan(double).- Parameters:
a- value whose arc tangent is to be calculated- Returns:
- arc tangent of
a. Returned value is in the range-pi/2throughpi/2.
-
toRadians
public static double toRadians(double angdeg) Converts an angle measured in degrees to angle measured in radians, using standard Java functionMath.toRadians(double).- Parameters:
angdeg- angle in degrees- Returns:
- the measurement of the angle
angdegin radians.
-
toDegrees
public static double toDegrees(double angrad) Converts an angle measured in radians to angle measured in degrees, using standard Java functionMath.toDegrees(double).- Parameters:
angrad- angle in radians- Returns:
- the measurement of the angle
angradin degrees.
-
exp
public static double exp(double a) Calculates Euler's numbereraised to the given power using standard Java functionMath.exp(double).- Parameters:
a- the exponent to raiseeto- Returns:
ea, where e is the base of natural logarithms.
-
log
public static double log(double a) Calculates the natural logarithm using standard Java functionMath.log(double).- Parameters:
a- the value whose logarithm is to be calculated- Returns:
ln a, the natural logarithm ofa. Ifa<0, the result isNaN. Ifa=0, the result is negative infinity.
-
log10
public static double log10(double a) Calculates the base 10 logarithm using standard Java functionMath.log10(double).- Parameters:
a- the value whose logarithm with base 10 is to be calculated- Returns:
log10a. Ifa<0, the result isNaN. Ifa=0, the result is negative infinity.
-
log
public static double log(double a, double b) Calculates logarithm ofbwith basea.- Parameters:
a- the base of the logarithmb- the value whose logarithm is to be calculated- Returns:
logab. For special values of a and b the result is:- if
a<0the result isNaN - if
a=0the result isNaNforb<=0and 0 forb>0 - if
0<a<1the result isNaNforb<0andInfinityforb=0 -
if
a=1the result isNaNforb<0,-Infinityfor0<b<1,NaNforb=1andInfinityforb>1 - if
a>1the result isNaNforb<0and-Infinityforb=0
- if
-
sqrt
public static double sqrt(double a) Calculates the positive square root using standard Java functionMath.sqrt(double).- Parameters:
a- the value whose square root is to be calculated- Returns:
- square root of
a. Ifa<0, the result isNaN.
-
cbrt
public static double cbrt(double a) Calculates the cube root using standard Java functionStrictMath.cbrt(double).- Parameters:
a- the value whose cube root is to be calculated- Returns:
- cube root of
a
-
ceil
public static double ceil(double a) Returns the smallest rounded to whole number value which is greater than or equal to the argument, using standard Java functionMath.ceil(double).- Parameters:
a- the value whose ceil is to be calculated- Returns:
- the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
-
floor
public static double floor(double a) Returns the largest rounded to whole number value which is less than or equal to the argument, using standard Java functionMath.floor(double).- Parameters:
a- the value whose floor is to be calculated- Returns:
- the largest (closest to positive infinity)
value that is less than or equal to
aand is equal to a mathematical integer.
-
pow
public static double pow(double a, double b) Returns the value of the first argument raised to the power of the second argument, calculated using standard Java functionMath.pow(double, double).- Parameters:
a- the baseb- the exponent- Returns:
ab
-
round
public static int round(float a) Returns the closestintto the argument, calculated using standard Java functionMath.round(float).- Parameters:
a- the value for which the closest integer is calculated- Returns:
- The
intclosest toa.Special cases:
- if
a<Integer.MIN_VALUE, the result isInteger.MIN_VALUE, else - if
a>Integer.MAX_VALUE, the result isInteger.MAX_VALUE, else -
if
ais in equal distance from the two closest ints, the result is the greater one (closer to positive infinity)
- if
-
round
public static double round(double a, int scale) Rounds the number to specified decimal places. Values approximately in equal distance to the two closest rounded numbers are rounded up.- Parameters:
a- the value to be roundedscale- number of decimal places. Negativescaleresults in rounding to the nearest integer number with the specified number of zeroes at the end of its decimal representation.- Returns:
- Multiple of 10
-scaleclosest toa. Ifais equal to the arithmetic average of the nearest multiples of 10-scaleor is a bit smaller, the value is rounded up. More specifically, the result is calculated as:floor(a * 10scale+ 0.5 + 0.000001) / 10scale - See Also:
-
trunc
public static double trunc(double a, int scale) Rounds the number to specified decimal places. Values are rounded down (to the number closer to negative infinity).- Parameters:
a- the value to be roundedscale- number of decimal places. Negativescaleresults in rounding to the closest integer number less than or equal toawith the specified number of zeroes at the end of its decimal representation.- Returns:
- Multiple of 10
-scaleclosest toa, less than or equal toa.
-
round
public static long round(double a) Returns the closestlongto the argument, with ties rounding to positive infinity, using standard Java functionMath.round(double).- Parameters:
a- the value to be rounded- Returns:
longclosest toa.- if
a<Long.MIN_VALUE, the result isLong.MIN_VALUE, else - if
a>Long.MAX_VALUE, the result isLong.MAX_VALUE, else -
if
ais in equal distance from the two closest longs, the result is the greater one (closer to positive infinity)
- if
-
random
public static double random()Returns a pseudo-random number greater than or equal to0.0and less than1.0, using standard Java functionMath.random()- Returns:
- a pseudorandom
doublegreater than or equal to0.0and less than1.0, with (approximately) uniform distribution.When this method is first called, it creates a new pseudo-random number generator, which is used thereafter for all calls to this method.
-
abs
public static int abs(int a) Returns absolute value of the argument using standard Java functionMath.abs(int).- Parameters:
a- the number whose absolute value is to be found- Returns:
- absolute value of
a.In special case when
a=Integer.MIN_VALUE, the result is also equal toInteger.MIN_VALUE, which is negative.
-
abs
public static long abs(long a) Returns absolute value of the argument using standard Java functionMath.abs(long).- Parameters:
a- the number whose absolute value is to be found- Returns:
- absolute value of
a.In special case when
a=Long.MIN_VALUE, the result is also equal toLong.MIN_VALUE, which is negative.
-
abs
public static float abs(float a) Returns absolute value of the argument using standard Java functionMath.abs(float).- Parameters:
a- the number whose absolute value is to be found- Returns:
- absolute value of
a.
-
abs
public static double abs(double a) Returns absolute value of the argument using standard Java functionMath.abs(double).- Parameters:
a- the number whose absolute value is to be found- Returns:
- absolute value of
a.
-
max
public static int max(int a, int b) Returns the greater of two values found using standard Java functionMath.max(int, int).- Parameters:
a- one valueb- another value- Returns:
- the larger of
aandb.
-
max
public static long max(long a, long b) Returns the greater of two values found using standard Java functionMath.max(long, long).- Parameters:
a- one valueb- another value- Returns:
- the larger of
aandb.
-
max
public static float max(float a, float b) Returns the greater of two values found using standard Java functionMath.max(float, float).- Parameters:
a- one valueb- another value- Returns:
- the larger of
aandb.
-
max
public static double max(double a, double b) Returns the greater of two values found using standard Java functionMath.max(double, double).- Parameters:
a- one valueb- another value- Returns:
- the larger of
aandb.
-
min
public static int min(int a, int b) Returns the smaller of two values found using standard Java functionMath.min(int, int).- Parameters:
a- one valueb- another value- Returns:
- the smaller of
aandb.
-
min
public static long min(long a, long b) Returns the smaller of two values found using standard Java functionMath.min(long, long).- Parameters:
a- one valueb- another value- Returns:
- the smaller of
aandb.
-
min
public static float min(float a, float b) Returns the smaller of two values found using standard Java functionMath.min(float, float).- Parameters:
a- one valueb- another value- Returns:
- the smaller of
aandb.
-
min
public static double min(double a, double b) Returns the smaller of two values found using standard Java functionMath.min(double, double).- Parameters:
a- one valueb- another value- Returns:
- the smaller of
aandb.
-
signum
public static double signum(double d) Returns the signum function of the argument, determined using standard Java functionMath.signum(double).- Parameters:
d- the number whose signum is determined- Returns:
- -1.0 if
d<0, - 0.0 if
d=0, - 1.0 if
d>0.
- -1.0 if
-
signum
public static float signum(float f) Returns the signum function of the argument, determined using standard Java functionMath.signum(float).- Parameters:
f- the number whose signum is determined- Returns:
- -1.0f if
d<0 - 0.0f if
d=0 - 1.0f if
d>0
- -1.0f if
-
sinh
public static double sinh(double x) Calculates the hyperbolic sine, using standard Java functionMath.sinh(double).- Parameters:
x- value, whose hyperbolic sine is to be calculated- Returns:
- the hyperbolic sine of
x.
-
cosh
public static double cosh(double x) Calculates the hyperbolic cosine, using standard Java functionMath.cosh(double).- Parameters:
x- value, whose hyperbolic cosine is to be calculated- Returns:
- the hyperbolic cosine of
x.
-