# Math functions
Name | Description | Complexity |
---|---|---|
fraction(Int, Int, Int): Int | Multiplies and divides integers to avoid overflow | 1 |
fraction(Int, Int, Int, Union): Int | Multiplies and divides integers to avoid overflow, applying the specified rounding method | 1 |
fraction(BigInt, BigInt, BigInt): BigInt | Multiplies and divides big integers to avoid overflow | 1 |
fraction(BigInt, BigInt, BigInt, Union): BigInt | Multiplies and divides big integers to avoid overflow, applying the specified rounding method | 1 |
log(Int, Int, Int, Int, Int, Union): Int | Calculates logarithm of a number to a given base | 100 |
log(BigInt, Int, BigInt, Int, Int, Union): BigInt | Calculates logarithm of a number to a given base with high accuracy | 200 |
median(List[Int]): Int | Returns the median of a list of integers | 20 |
median(List[BigInt]): BigInt | Returns the median of a list of big integers | 35 for Standard library version 8 160 for Standard library version 7 or 6 |
pow(Int, Int, Int, Int, Int, Union): Int | Raises a number to a given power | 28 |
pow(BigInt, Int, BigInt, Int, Int, Union): BigInt | Raises a number to a given power with high accuracy | 270 |
sqrt(Int, Int, Int, Union): Int | Returns the square root of a number | 2 |
sqrt(BigInt, Int, Int, Union): BigInt | Returns the square root of a number with high accuracy | 5 |
# fraction(Int, Int, Int): Int
Multiplies integers a
, b
and divides the result by the integer c
to avoid overflow.
Fraction a × b / c
should not exceed the maximum value of the integer type 9,223,372,036,854,755,807.
The rounding method is DOWN, see Rounding variables below.
fraction(a: Int, b: Int, c: Int): Int
# Parameters
Parameter | Description |
---|---|
a : Int | Integer a |
b : Int | Integer b |
c : Int | Integer c |
# Example
Lets assume that:
a = 100,000,000,000,
b = 50,000,000,000,000,
c = 2,500,000.
The following formula, with operators *
and /
, fails due to overflow:
a * b / c # overflow, because a × b exceeds max integer value
The fraction function with no overflow:
fraction(a, b, c) # Result: 2,000,000,000,000,000,000
# fraction(Int, Int, Int, Union): Int
Multiplies integers a
, b
and divides the result by the integer c
to avoid overflow, applying the specified rounding method.
Fraction a × b / c
should not exceed the maximum value of the integer type 9,223,372,036,854,755,807.
fraction(a: Int, b: Int, c: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int
# Parameters
Parameter | Description |
---|---|
a : Int | Integer a |
b : Int | Integer b |
c : Int | Integer c |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# fraction(BigInt, BigInt, BigInt): BigInt
Multiplies big integers a
, b
and divides the result by the integer c
to avoid overflow.
Fraction a × b / c
should not exceed the maximum value of the big integer type.
The rounding method is DOWN, see Rounding variables below.
fraction(a: BigInt, b: BigInt, c: BigInt): BigInt
# Parameters
Parameter | Description |
---|---|
a : BigInt | Big integer a |
b : BigInt | Big integer b |
c : BigInt | Big integer c |
# fraction(BigInt, BigInt, BigInt, Union): BigInt
Multiplies big integers a
, b
and divides the result by the integer c
to avoid overflow, applying the specified rounding method.
Fraction a × b / c
should not exceed the maximum value of the big integer type.
fraction(a: BigInt, b: BigInt, c: BigInt, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt
# Parameters
Parameter | Description |
---|---|
a : BigInt | Big integer a |
b : BigInt | Big integer b |
c : BigInt | Big integer c |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# log(Int, Int, Int, Int, Int, Union): Int
Calculates log
b
a
.
log(value: Int, vp: Int, base: Int, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate log
2.716.25 then the number value
= 1625, vp
= 2 and the base
= 27, bp
= 1.
More examples:
a | value | vp |
---|---|---|
16.25 | 1625 | 2 |
5 | 5 | 0 |
5.00 | 500 | 2 |
If the log
function returns, for example, 2807, and the parameter rp
= 3, then the result is 2.807; in the number 2807 the last 3 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
value : Int | Number a without decimal point |
vp : Int | Number of decimals of a , from 0 to 8 inclusive |
base : Int | Logarithm base b without decimal point |
bp : Int | Number of decimals of b , from 0 to 8 inclusive |
rp : Int | Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# Examples
log
2.716.25 = 2.807035421...
log(1625, 2, 27, 1, 2, HALFUP) # Function returns 281, so the result is: 2.81
log(1625, 2, 27, 1, 5, HALFUP) # Function returns 280703542, so the result is: 2.80704
log(0, 0, 2, 0, 0, HALFUP) # Result: -Infinity
# log(BigInt, Int, BigInt, Int, Int, Union): BigInt
Calculates log
b
a
with high accuracy.
log(value: BigInt, vp: Int, base: BigInt, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate log
2.716.25 then value
= 1625, vp
= 2 and the base
= 27, bp
= 1.
If the log
function returns, for example, 2807035420964590265, and the parameter rp
= 18, then the result is 2.807035420964590265; in the number 2807035420964590265 the last 18 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
value : BigInt | Number a without decimal point |
vp : Int | Number of decimals of a , from 0 to 18 inclusive |
base : BigInt | Logarithm base b without decimal point |
bp : Int | Number of decimals of b , from 0 to 18 inclusive |
rp : Int | Number of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# median(List[Int]): Int
Returns the median of the list of integers. Fails if the list is empty.
median(arr: List[Int]): Int
# Parameters
Parameter | Description |
---|---|
arr : List[Int] | List of integers |
# Examples
median([1, 2, 3]) # Returns 2
median([2, 4, 9, 20]) # Returns 6
median([-2, -4, -9, -20]) # Returns -7
# median(List[BigInt]): BigInt
Returns the median of a list of big integers. Fails if the list is empty or contains more than 100 elements.
median(arr: List[BigInt]): BigInt
# Parameters
Parameter | Description |
---|---|
arr : List[BigInt] | List of big integers |
# pow(Int, Int, Int, Int, Int, Union): Int
Calculates a
b
.
pow(base: Int, bp: Int, exponent: Int, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate 16.252.7, then the number base
= 1625, bp
= 2, and the exponent
= 27, ep
= 1.
If the pow
function returns, for example, 18591057, and the parameter rp
= 4, then the result is 1859.1057; in the number 18591057 the last 4 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
base : Int | Number a without decimal point |
bp : Int | Number of decimals of a , from 0 to 8 inclusive |
exponent : Int | Exponent b without decimal point |
ep : Int | Number of decimals of b , from 0 to 8 inclusive |
rp : Int | Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# Examples
16.252.7 = 1859,1057168...
pow(1625, 2, 27, 1, 2, HALFUP) # function returns 185911, so the result is: 1859.11
pow(1625, 2, 27, 1, 5, HALFUP) # function returns 185910572, so, the result is: 1859.10572
# pow(BigInt, Int, BigInt, Int, Int, Union): BigInt
Calculates a
b
with high accuracy.
pow(base: BigInt, bp: Int, exponent: BigInt, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate 16.252.7, then the number base
= 1625, bp
= 2, and the exponent
= 27, ep
= 1.
If the pow
function returns, for example, 1859105716849757217692, and the parameter rp
= 18, then the result is 1859.105716849757217692; in the number 1859105716849757217692 the last 18 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
base : BigInt | Number a without decimal point |
bp : Int | Number of decimals of a , from 0 to 18 inclusive |
exponent : BigInt | Exponent b without decimal point |
ep : Int | Number of decimals of b , from 0 to 18 inclusive |
rp : Int | Number of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# sqrt(Int, Int, Int, Union): Int
Calculates the square root of a number: √a
.
sqrt(base: Int, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate √16.25, specify base
= 1625 and bp
= 2.
If the sqrt
function returns, for example, 40311, and the parameter rp
= 4, then the result is 4.0311; in the number 40311 the last 4 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
base : Int | Number a without decimal point |
bp : Int | Number of decimals of a |
rp : Int | Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# Examples
√16,25 = 4,03112887...
sqrt(1625, 2, 2, HALFUP) # function returns 403, so the result is 4.03
sqrt(1625, 2, 5, HALFUP) # function returns 403113, so the result is 4.03113
# sqrt(BigInt, Int, Int, Union): BigInt
Calculates the square root of a number with high accuracy.
sqrt(base: BigInt, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt
In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate √16.25, specify base
= 1625 and bp
= 2.
If the sqrt
function returns, for example, 4031128874149274826, and the parameter rp
= 18, then the result is 4.031128874149274826; in the number 4031128874149274826 the last 18 digits is a fractional part.
# Parameters
Parameter | Description |
---|---|
base : BigInt | Number a without decimal point |
bp : Int | Number of decimals of a |
rp : Int | Number of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result |
round : DOWN|CEILING|FLOOR|HALFUP|HALFEVEN | One of the rounding variables |
# Rounding Variables
Below is the list of built-in rounding variables. Every variable corresponds to the rounding method.
The rounding variables are only used as the parameters of functions fraction
, log
, pow
.
Name | Description |
---|---|
DOWN | Rounds towards zero |
CEILING | Rounds towards positive infinity |
FLOOR | Rounds towards negative infinity |
HALFUP | Rounds towards the nearest integer; if the integers are equidistant, then rounds away from zero |
HALFEVEN | Rounds towards the nearest integer; if the integers are equidistant, then rounds towards the nearest even integer |
# Examples
Input number/Rounding method | DOWN | CEILING | FLOOR | HALFUP | HALFEVEN |
---|---|---|---|---|---|
5.5 | 5 | 6 | 5 | 6 | 6 |
2.5 | 2 | 3 | 2 | 3 | 2 |
1.6 | 1 | 2 | 1 | 2 | 2 |
1.1 | 1 | 2 | 1 | 1 | 1 |
1.0 | 1 | 1 | 1 | 1 | 1 |
-1.0 | -1 | -1 | -1 | -1 | -1 |
-1.1 | -1 | -1 | -2 | -1 | -1 |
-1.6 | -1 | -1 | -2 | -2 | -2 |
-2.5 | -2 | -2 | -3 | -3 | -2 |
-5.5 | -5 | -5 | -6 | -6 | -6 |