Calculation
Documentation for the calc functions.
Module for calculations and processing of numeric values.
These definitions are part of the calc module and not imported by default. In addition to the functions listed below, the calc module also defines the constants pi, tau, e, and inf.
Calculates the absolute value of a numeric value.
#calc.abs(
value
) -> anyParameters
Prop
Type
Raises a value to some exponent.
#calc.pow(
base,
exponent
) -> int float decimalParameters
Prop
Type
Raises a value to some exponent of e.
#calc.exp(
exponent
) -> floatParameters
Prop
Type
Calculates the square root of a number.
#calc.sqrt(
value
) -> floatParameters
Prop
Type
Calculates the real nth root of a number.
If the number is negative, then n must be odd.
#calc.root(
radicand,
index
) -> floatParameters
Prop
Type
Calculates the sine of an angle.
When called with an integer or a float, they will be interpreted as radians.
#calc.sin(
angle
) -> floatParameters
Prop
Type
Calculates the cosine of an angle.
When called with an integer or a float, they will be interpreted as radians.
#calc.cos(
angle
) -> floatParameters
Prop
Type
Calculates the tangent of an angle.
When called with an integer or a float, they will be interpreted as radians.
#calc.tan(
angle
) -> floatParameters
Prop
Type
Calculates the arcsine of a number.
#calc.asin(
value
) -> angleParameters
Prop
Type
Calculates the arccosine of a number.
#calc.acos(
value
) -> angleParameters
Prop
Type
Calculates the arctangent of a number.
#calc.atan(
value
) -> angleParameters
Prop
Type
Calculates the four-quadrant arctangent of a coordinate.
The arguments are (x, y), not (y, x).
#calc.atan2(
x,
y
) -> angleParameters
Prop
Type
Calculates the hyperbolic sine of a hyperbolic angle.
#calc.sinh(
value
) -> floatParameters
Prop
Type
Calculates the hyperbolic cosine of a hyperbolic angle.
#calc.cosh(
value
) -> floatParameters
Prop
Type
Calculates the hyperbolic tangent of a hyperbolic angle.
#calc.tanh(
value
) -> floatParameters
Prop
Type
Calculates the logarithm of a number.
If the base is not specified, the logarithm is calculated in base 10.
#calc.log(
value,
base: float
) -> floatParameters
Prop
Type
Calculates the natural logarithm of a number.
#calc.ln(
value
) -> floatParameters
Prop
Type
Calculates the factorial of a number.
#calc.fact(
number
) -> intParameters
Prop
Type
Calculates a permutation.
Returns the k-permutation of n, or the number of ways to choose k items from a set of n with regard to order.
#calc.perm(
base,
numbers
) -> intParameters
Prop
Type
Calculates a binomial coefficient.
Returns the k-combination of n, or the number of ways to choose k items from a set of n without regard to order.
#calc.binom(
n,
k
) -> intParameters
Prop
Type
Calculates the greatest common divisor of two integers.
This will error if the result of integer division would be larger than the maximum 64-bit signed integer.
#calc.gcd(
a,
b
) -> intParameters
Prop
Type
Calculates the least common multiple of two integers.
#calc.lcm(
a,
b
) -> intParameters
Prop
Type
Rounds a number down to the nearest integer.
If the number is already an integer, it is returned unchanged.
Note that this function will always return an integer, and will error if the resulting float or decimal is larger than the maximum 64-bit signed integer or smaller than the minimum for that type.
#calc.floor(
value
) -> intParameters
Prop
Type
Rounds a number up to the nearest integer.
If the number is already an integer, it is returned unchanged.
Note that this function will always return an integer, and will error if the resulting float or decimal is larger than the maximum 64-bit signed integer or smaller than the minimum for that type.
#calc.ceil(
value
) -> intParameters
Prop
Type
Returns the integer part of a number.
If the number is already an integer, it is returned unchanged.
Note that this function will always return an integer, and will error if the resulting float or decimal is larger than the maximum 64-bit signed integer or smaller than the minimum for that type.
#calc.trunc(
value
) -> intParameters
Prop
Type
Returns the fractional part of a number.
If the number is an integer, returns 0.
#calc.fract(
value
) -> int float decimalParameters
Prop
Type
Rounds a number to the nearest integer.
Half-integers are rounded away from zero.
Optionally, a number of decimal places can be specified. If negative, its absolute value will indicate the amount of significant integer digits to remove before the decimal point.
Note that this function will return the same type as the operand. That is, applying round to a float will return a float, and to a decimal, another decimal. You may explicitly convert the output of this function to an integer with int, but note that such a conversion will error if the float or decimal is larger than the maximum 64-bit signed integer or smaller than the minimum integer.
In addition, this function can error if there is an attempt to round beyond the maximum or minimum integer or decimal. If the number is a float, such an attempt will cause float.inf or -float.inf to be returned for maximum and minimum respectively.
#calc.round(
value,
digits: int
) -> int float decimalParameters
Prop
Type
Clamps a number between a minimum and maximum value.
#calc.clamp(
value,
min,
max
) -> int float decimalParameters
Prop
Type
Determines the minimum of a sequence of values.
#calc.min(
values
) -> anyParameters
Prop
Type
Determines the maximum of a sequence of values.
#calc.max(
values
) -> anyParameters
Prop
Type
Determines whether an integer is even.
#calc.even(
value
) -> boolParameters
Prop
Type
Determines whether an integer is odd.
#calc.odd(
value
) -> boolParameters
Prop
Type
Calculates the remainder of two numbers.
The value calc.rem(x, y) always has the same sign as x, and is smaller in magnitude than y.
This can error if given a decimal input and the dividend is too small in magnitude compared to the divisor.
#calc.rem(
dividend,
divisor
) -> int float decimalParameters
Prop
Type
Performs euclidean division of two numbers.
The result of this computation is that of a division rounded to the integer n such that the dividend is greater than or equal to n times the divisor.
This can error if the resulting number is larger than the maximum value or smaller than the minimum value for its type.
#calc.div-euclid(
dividend,
divisor
) -> int float decimalParameters
Prop
Type
This calculates the least nonnegative remainder of a division.
Warning: Due to a floating point round-off error, the remainder may equal the absolute value of the divisor if the dividend is much smaller in magnitude than the divisor and the dividend is negative. This only applies for floating point inputs.
In addition, this can error if given a decimal input and the dividend is too small in magnitude compared to the divisor.
#calc.rem-euclid(
dividend,
divisor
) -> int float decimalParameters
Prop
Type
Calculates the quotient (floored division) of two numbers.
Note that this function will always return an integer, and will error if the resulting number is larger than the maximum 64-bit signed integer or smaller than the minimum for that type.
#calc.quo(
dividend,
divisor
) -> intParameters
Prop
Type
Calculates the p-norm of a sequence of values.
#calc.norm(
p: float,
values
) -> floatParameters
Prop
Type