pdk.util.Math
contains functions to support math operations
Functions
absInt
Returns the absolute value of an integer value.
Arguments:
input :: pdk.core.Integer - the argument whose absolute value is to be determined.
Result:
output :: pdk.core.Integer - the absolute value of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
absFloat
Returns the absolute value of an float value.
Arguments:
input :: pdk.core.Float - the argument whose absolute value is to be determined.
Result:
output :: pdk.core.Float - the absolute value of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
acos
Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.
Special case - If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - the value whose arc cosine is to be returned.
Result:
output :: pdk.core.Float - the arc cosine of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
asin
Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:
If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
Arguments:
input :: pdk.core.Float - the value whose arc sine is to be returned.
Result:
output :: pdk.core.Float - the arc sine of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
atan
Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:
If the argument is NaN, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - the value whose arc tangent is to be returned.
Result:
output :: pdk.core.Float - the arc tangent of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
cbrt
Returns the cube root of a float value. For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value's magnitude. Special cases:
If the argument is NaN, then the result is NaN.
If the argument is infinite, then the result is an infinity with the same sign as the argument.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result.
Arguments:
input :: pdk.core.Float - a value.
Result:
output :: pdk.core.Float - the cube root of a.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
ceil
Returns the smallest (closest to negative infinity) float value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x).
Arguments:
input :: pdk.core.Float - a value.
Result:
output :: pdk.core.Integer - the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
cos
Returns the trigonometric cosine of an angle.Special cases:
If the argument is NaN or an infinity, then the result is NaN.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - an angle, in radians.
Result:
output :: pdk.core.Float - the cosine of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
cosh
Returns the hyperbolic cosine of x.
Arguments:
input :: pdk.core.Float - value for which to find the hyperbolic cosine.
Result:
output :: pdk.core.Float - hyperbolic cosine of x.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
exp
Returns Euler's number e raised to the power of a float value. Special cases:
If the argument is NaN or an infinity, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is negative infinity, then the result is positive zero.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - the exponent to raise e to.
Result:
output :: pdk.core.Float - the value eFloat, where e is the base of the natural logarithms.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
expm1
Compute exp(x) - 1.
Arguments:
input :: pdk.core.Float - number to compute shifted exponential.
Result:
output :: pdk.core.Float - exp(x) - 1.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
floor
Returns the largest (closest to positive infinity) integer value that is less than or equal to the argument. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Arguments:
input :: pdk.core.Float - a value.
Result:
output :: pdk.core.Float - the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
factorial
Returns n!. Shorthand for n Factorial, the product of the numbers 1,...,n.
Arguments:
input :: pdk.core.Integer - argument.
Result:
output :: pdk.core.Integer - n!.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
gcd
Gets the greatest common divisor of the absolute value of two numbers, using the 'binary gcd' method which avoids division and modulo operations. See Knuth 4.5.2 algorithm B. This algorithm is due to Josef Stein (1961).
Arguments:
number1 :: pdk.core.Integer
number2 :: pdk.core.Integer
Result:
output :: pdk.core.Integer - the greatest common divisor, never negative.
Possible exceptions
NullPointerException - throws if the number1 or number2 argument is
NULL
hypot
Returns the hypotenuse of a triangle with sides x and y - sqrt(x2 +y2) avoiding intermediate overflow or underflow.
Arguments:
leg1 :: pdk.core.Float - the first leg.
leg2 :: pdk.core.Float - the second leg.
Result:
output :: pdk.core.Float - returns the hypotenuse of a triangle with sides x and y - sqrt(pow(x, 2) + pow(y, 2)).
Possible exceptions
NullPointerException - throws if the leg1 or leg2 argument is
NULL
lcm
Returns the least common multiple of the absolute value of two numbers, using the formula lcm(a,b) = (a / gcd(a,b)) * b.
Arguments:
num1 :: pdk.core.Integer
num2 :: pdk.core.Integer
Result:
output :: pdk.core.Integer - the least common multiple, never negative.
Possible exceptions
NullPointerException - throws if the num1 or num2 argument is
NULL
log
Returns the natural logarithm (base e) of a float value. Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is negative infinity.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Returns the least common multiple of the absolute value of two numbers, using the formula lcm(a,b) = (a / gcd(a,b)) * b.
Arguments:
input :: pdk.core.Float
Result:
output :: pdk.core.Float - the value ln, the natural logarithm.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
log10
Returns the base 10 logarithm of a float value.Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is negative infinity.
If the argument is equal to 10n for integer n, then the result is n.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float
Result:
output :: pdk.core.Float - the base 10 logarithm.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
maxFloat
Returns the greater of two float values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.
Arguments:
input1 :: pdk.core.Float
input2 :: pdk.core.Float
Result:
output :: pdk.core.Float - the larger of the arguments.
Possible exceptions
NullPointerException - throws if the input1 or input2 argument is
NULL
maxFloatValue
Returns maximum value a Flow can have, (2 - Math.pow(2,-52)) * Math.pow(2,1023).
Arguments:
no
Result:
output :: pdk.core.Float - max possible value.
maxInt
Returns the greater of two integer values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.
Arguments:
num1 :: pdk.core.Integer
num2 :: pdk.core.Integer
Result:
output :: pdk.core.Integer - the larger of the arguments.
Possible exceptions
NullPointerException - throws if the num1 or num2 argument is
NULL
maxIntegerValue
Returns maximum value an Integer can have, Math.pow(2,63)-1.
Arguments:
no
Result:
output :: pdk.core.Integer - max possible value.
minFloat
Returns the smaller of two float values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.
Arguments:
input1 :: pdk.core.Float
input2 :: pdk.core.Float
Result:
output :: pdk.core.Float - the smaller of the arguments.
Possible exceptions
NullPointerException - throws if the input1 or input2 argument is
NULL
minFloatValue
Returns minimum value a Flow can have, -(2 - Math.pow(2,-52)) * Math.pow(2,1023).
Arguments:
no
Result:
output :: pdk.core.Float - min possible value.
minInt
Returns the smaller of two integer values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.
Arguments:
num1 :: pdk.core.Integer
num2 :: pdk.core.Integer
Result:
output :: pdk.core.Integer - the smalest of the arguments.
Possible exceptions
NullPointerException - throws if the num1 or num2 argument is
NULL
minIntegerValue
Returns minimum value an Integer can have, -Math.pow(2,63).
Arguments:
no
Result:
output :: pdk.core.Integer - min possible value.
pow
Returns the value of the first argument raised to the power of the second argument.
Arguments:
num1 :: pdk.core.Integer
num2 :: pdk.core.Integer
Result:
output :: pdk.core.Integer - the result.
Possible exceptions
NullPointerException - throws if the num1 or num2 argument is
NULL
random
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
Arguments:
no
Result:
output :: pdk.core.Float - a pseudorandom float greater than or equal to 0.0 and less than 1.0.
round
Returns the closest int to the argument, with ties rounding up.Special cases:
If the argument is NaN, the result is 0.
If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.
Arguments:
input :: pdk.core.Float - a floating-point value to be rounded to an integer.
Result:
output :: pdk.core.Integer - the value of the argument rounded to the nearest integer value.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
roundFloat
Rounding mode to round towards nearest neighbor, unless both neighbors are equidistant, in which case round up.
Arguments:
input :: pdk.core.Float - the floating-point value.
scale :: pdk.core.Integer - the value of the argument rounded to the scale value.
Result:
output :: pdk.core.Float - a floating-point value.
Possible exceptions
NullPointerException - throws if the input or scale argument is
NULL
sign
Returns the sign for number x.
Arguments:
input :: pdk.core.Number - any number.
Result:
output :: pdk.core.Integer - +1, 0, or -1, depending on the sign of x.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
sin
Returns the trigonometric sine of an angle. Special cases:
If the argument is NaN or an infinity, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - an angle, in radians.
Result:
output :: pdk.core.Float - the sine of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
sinh
Returns the hyperbolic sine.
Arguments:
input :: pdk.core.Float - double value for which to find the hyperbolic sine.
Result:
output :: pdk.core.Float - hyperbolic sine.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
sqrt
Returns the correctly rounded positive square root of a double value. Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is the same as the argument.
Otherwise, the result is the double value closest to the true mathematical square root of the argument value.
Arguments:
input :: pdk.core.Float - a value.
Result:
output :: pdk.core.Float - the positive square root of the argument. If the argument is NaN or less than zero, the result is NaN.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
tan
Returns the trigonometric tangent of an angle. Special cases:
If the argument is NaN or an infinity, then the result is NaN.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Arguments:
input :: pdk.core.Float - an angle, in radians.
Result:
output :: pdk.core.Float - the tangent of the argument.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
toDegrees
Convert radians to degrees, with error of less than 0.5 ULP.
Arguments:
input :: pdk.core.Float - an angle, in radians.
Result:
output :: pdk.core.Float - converted into degrees.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
toRadians
Convert degrees to radians, with error of less than 0.5 ULP.
Arguments:
input :: pdk.core.Float - an angle, in degrees.
Result:
output :: pdk.core.Float - converted into radians.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
Last updated