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:

Possible exceptions


absFloat

Returns the absolute value of an float value.

Arguments:

  • input :: pdk.core.Float - the argument whose absolute value is to be determined.

Result:

Possible exceptions


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:

Possible exceptions


asin

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:

  1. If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

  2. If the argument is zero, then the result is a zero with the same sign as the argument.

Arguments:

Result:

Possible exceptions


atan

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:

  1. If the argument is NaN, then the result is NaN.

  2. 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:

Possible exceptions


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:

  1. If the argument is NaN, then the result is NaN.

  2. If the argument is infinite, then the result is an infinity with the same sign as the argument.

  3. 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:

Result:

Possible exceptions


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:

  1. If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

  2. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

  3. 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:

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


cos

Returns the trigonometric cosine of an angle.Special cases:

  1. 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:

Result:

Possible exceptions


cosh

Returns the hyperbolic cosine of x.

Arguments:

  • input :: pdk.core.Float - value for which to find the hyperbolic cosine.

Result:

Possible exceptions


exp

Returns Euler's number e raised to the power of a float value. Special cases:

  1. If the argument is NaN or an infinity, then the result is NaN.

  2. If the argument is positive infinity, then the result is positive infinity.

  3. 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:

Result:

  • output :: pdk.core.Float - the value eFloat, where e is the base of the natural logarithms.

Possible exceptions


expm1

Compute exp(x) - 1.

Arguments:

Result:

Possible exceptions


floor

Returns the largest (closest to positive infinity) integer value that is less than or equal to the argument. Special cases:

  1. If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

  2. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Arguments:

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


factorial

Returns n!. Shorthand for n Factorial, the product of the numbers 1,...,n.

Arguments:

Result:

Possible exceptions


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:

Result:

Possible exceptions


hypot

Returns the hypotenuse of a triangle with sides x and y - sqrt(x2 +y2) avoiding intermediate overflow or underflow.

Arguments:

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


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:

Result:

Possible exceptions


log

Returns the natural logarithm (base e) of a float value. Special cases:

  1. If the argument is NaN or less than zero, then the result is NaN.

  2. If the argument is positive infinity, then the result is positive infinity.

  3. 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:

Result:

Possible exceptions


log10

Returns the base 10 logarithm of a float value.Special cases:

  1. If the argument is NaN or less than zero, then the result is NaN.

  2. If the argument is positive infinity, then the result is positive infinity.

  3. If the argument is positive zero or negative zero, then the result is negative infinity.

  4. 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:

Result:

Possible exceptions


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:

Result:

Possible exceptions


maxFloatValue

Returns maximum value a Flow can have, (2 - Math.pow(2,-52)) * Math.pow(2,1023).

Arguments:

  • no

Result:


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:

Result:

Possible exceptions


maxIntegerValue

Returns maximum value an Integer can have, Math.pow(2,63)-1.

Arguments:

  • no

Result:


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:

Result:

Possible exceptions


minFloatValue

Returns minimum value a Flow can have, -(2 - Math.pow(2,-52)) * Math.pow(2,1023).

Arguments:

  • no

Result:


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:

Result:

Possible exceptions


minIntegerValue

Returns minimum value an Integer can have, -Math.pow(2,63).

Arguments:

  • no

Result:


pow

Returns the value of the first argument raised to the power of the second argument.

Arguments:

Result:

Possible exceptions


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:

  1. If the argument is NaN, the result is 0.

  2. 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.

  3. 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


roundFloat

Rounding mode to round towards nearest neighbor, unless both neighbors are equidistant, in which case round up.

Arguments:

Result:

Possible exceptions


sign

Returns the sign for number x.

Arguments:

Result:

Possible exceptions


sin

Returns the trigonometric sine of an angle. Special cases:

  1. If the argument is NaN or an infinity, then the result is NaN.

  2. 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:

Result:

Possible exceptions


sinh

Returns the hyperbolic sine.

Arguments:

  • input :: pdk.core.Float - double value for which to find the hyperbolic sine.

Result:

Possible exceptions


sqrt

Returns the correctly rounded positive square root of a double value. Special cases:

  1. If the argument is NaN or less than zero, then the result is NaN.

  2. If the argument is positive infinity, then the result is positive infinity.

  3. 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:

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


tan

Returns the trigonometric tangent of an angle. Special cases:

  1. If the argument is NaN or an infinity, then the result is NaN.

  2. 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:

Result:

Possible exceptions


toDegrees

Convert radians to degrees, with error of less than 0.5 ULP.

Arguments:

Result:

Possible exceptions


toRadians

Convert degrees to radians, with error of less than 0.5 ULP.

Arguments:

Result:

Possible exceptions

Last updated