Skip to content

Mathematical functions

The luego.math package contains common mathematical functions.

luego.math

abs

abs(x: X < AnyNumber) => X < AnyNumber

Returns the absolute value of the numeric argument

acos

acos(x: Number) => Number

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi

acosSafe

acosSafe(x: Number) => Option[Number]

Returns the arc cosine of a value wrapped in an option; the returned angle is in the range 0.0 through pi

addVectors

addVectors(v1: List[Number], v2: List[Number]) => List[Number]

Sum of two vectors of numbers v1 and v2

addVectorsI

addVectorsI(v1: List[Integer], v2: List[Integer]) => List[Integer]

Sum of two vectors of integers v1 and v2

approxEq

approxEq(x: Number, y: Number, precision: Number) => Boolean

Approximately equals

approxEqBD

approxEqBD(x: BigDecimal, y: BigDecimal, precision: BigDecimal) => Boolean

Approximately equals for big decimals

areaOfCircle

areaOfCircle(r: Number) => Number

Returns the area of a circle of radius r

asin

asin(x: Number) => Number

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

asinSafe

asinSafe(x: Number) => Number

Returns the arc sine of a value wrapped in an option; the returned angle is in the range -pi/2 through pi/2

atan

atan(x: Number) => Number

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

cbrt

cbrt(x: Number) => Number

Returns the cube root of a double value

ceil

ceil(x: Number) => Long

Returns the smallest (closest to negative infinity) long value that is greater than or equal to the argument

ceilInt

ceilInt(x: Number) => Integer

Returns the smallest (closest to negative infinity) integer value that is greater than or equal to the argument

cos

cos(a: Number) => Number

Returns the trigonometric cosine of an angle a

cosh

cosh(x: Number) => Number

Returns the hyperbolic cosine of a double value

divideAndRemainder

divideAndRemainder(x: BigDecimal, y: BigDecimal) => (BigDecimal,BigDecimal)

Returns a tuple containing the integer part of the quotient (x / y) rounded down and the remainder (x % y)

divSafe

divSafe(x: Integer, y: Integer) => Option[Integer]

Returns the division of two integers wrapped in an option in case the divider is zero

E

E() => Number

The double value that is closer than any other to e, the base of the natural logarithms

exp

exp(x: Number) => Number

Returns Euler's number e raised to the power of a double value

floor

floor(x: Number) => Long

Returns the largest (closest to positive infinity) long value that is less than or equal to the argument

floorDiv

floorDiv(x: Long, y: Long) => Long

Divides the first parameter by the second one, and then performs a floor operation over the result, returning the Long that is less or equal to the quotient

floorInt

floorInt(x: Number) => Integer

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

hypot

hypot(x: Number, y: Number) => Number

Returns sqrt(xx + yy) without intermediate overflow or underflow

IntegerMax

IntegerMax() => Integer

The largest value representable as an Integer

IntegerMin

IntegerMin() => Integer

The smallest value representable as an Integer

log

log(x: Number) => Number

Returns the natural logarithm (base e) of a double value

log10

log10(x: Number) => Number

Returns the base 10 logarithm of a double value

LongMax

LongMax() => Long

The largest value representable as a Long

LongMin

LongMin() => Long

The smallest value representable as a Long

max

max(x: X < AnyNumber, y: X < AnyNumber) => X < AnyNumber

Returns the larger of two numeric values

min

min(x: X < AnyNumber, y: X < AnyNumber) => X < AnyNumber

Returns the smaller of two numeric values

NumberMax

NumberMax() => Number

The largest value representable as a Double

NumberMin

NumberMin() => Number

The smallest value representable as a Double

Pi

Pi() => Number

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter

polynomial

polynomial(coefficients: List[Number], x: Number) => Number

Evaluate a polynomial with passed coefficients at x. The array of coefficients must have at least one element.

pow

pow(x: Number, y: Number) => Number

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

powBD

powBD(x: BigDecimal, y: BigDecimal) => BigDecimal

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

random

random() => Number

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0

round

round(x: Number) => Long

Returns the closest Long to the argument

roundInt

roundInt(x: Number) => Integer

Returns the closest Int to the argument

scale

scale(x: BigDecimal, s: Integer) => BigDecimal

Returns a new BigDecimal with scale s

scaleAndRounding

scaleAndRounding(x: BigDecimal, s: Integer, roundingType: Text) => BigDecimal

Returns a new BigDecimal with scale s and rounding r

signum

signum(x: X < AnyNumber) => Integer

Returns the signum of the argument: zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero

sin

sin(a: Number) => Number

Returns the trigonometric sine of an angle a

sinh

sinh(x: Number) => Number

Returns the hyperbolic sine of a double value

sqrt

sqrt(x: Number) => Number

Returns the correctly rounded positive square root of a double value

sqrtSafe

sqrtSafe(x: Number) => Option[Number]

Returns the correctly rounded square root of a double value wrapped in an option

tan

tan(a: Number) => Number

Returns the trigonometric tangent of an angle a

tanh

tanh(x: Number) => Number

Returns the hyperbolic tangent of a double value

toDegrees

toDegrees(x: Number) => Number

Converts an angle measured in radians to an approximately equivalent angle measured in degrees

toRadians

toRadians(x: Number) => Number

Converts an angle measured in degrees to an approximately equivalent angle measured in radians

volumeOfSphere

volumeOfSphere(r: Number) => Number

Returns the volume of a sphere of radius r