Math functions

# Name Description Complexity
1 fraction(Int, Int, Int): Int Converts arbitrarily large signed integer to integer 1
2 log(Int, Int, Int, Int, Int, Union): Int Calculates logarithm of the number 100
3 pow(Int, Int, Int, Int, Int, Union): Int Raises the number to a power 100

fraction(Int, Int, Int): Int

Converts arbitrarily large signed integer to integer.

fraction(value: Int, numerator: Int, denominator: Int): Int

Parameters

value: Int

Arbitrarily large signed integer.

numerator: Int

Numerator of the fraction.

denominator: Int

Denominator of the fraction.

Conversion formula

Conversion is performed according to the following formula:

fraction = value × numerator / denominator

Examples

fraction(2,2,3) # Returns 1
fraction(3,3,3) # Returns 3
fraction(3,2,3) # Returns 2

log(Int, Int, Int, Int, Int, Union): Int

Calculates logarithm of the number.

log(value: Int, ep: Int, base: Int, bp: Int, rp: Int, round: Union): Int

Parameters

value: Int

Given number.

ep: Int

Number of decimals of the given number.

base: Int

Base of the logarithm.

bp: Int

Number of decimals of the base.

rp: Int

Number of decimals of the resulting value.

round: Union

One of the rounding function.

The HalfUp() function may be used as the default value.

Examples

  • log2(0) = -Infinity
  • log2(2) = 0
  • log2(10.555) = 3.4
  • log2(16.25) = 4.02
log(0, 0, 2, 0, 0, HalfUp()) # -Infinity
log(1, 0, 2, 0, 0, HalfDown()) # Returns 0
log(10555, 3, 2, 0, 3, HalfEven()) # Returns 3400
log(1625, 2, 2, 0, 2, Up()) # Returns 403

pow(Int, Int, Int, Int, Int, Union): Int

Raises the number to a power.

pow(base: Int, bp: Int, exponent: Int, ep: Int, rp: Int, round: Union): Int

Parameters

base: Int

Given number.

bp: Int

Number of decimals of the given number.

exponent: Int

Power.

ep: Int

Number of decimals of power.

rp: Int

Number of decimals of the resulting value.

round: Union

One of the rounding functions.

The HalfUp() function may be used as the default value.

Examples

  • 10 = 1
  • 24 = 16
  • 2.52.5 = 9.88
  • 3.333 = 36.926
pow(1, 0, 0, 0, 0, Up()) # Returns 1
pow(2, 0, 4, 0, 0, HalfUp()) # Returns 16
pow(25, 1, 25, 1, 2, Floor()) # Returns 988
pow(333, 2, 3, 0, 3, Down()) # Returns 36926

Rounding functions

The rounding functions are only used as the parameters of log and pow functions and they are not used by themselves.

Name Description
Ceiling(): Int Rounding towards positive infinity
Down(): Int Rounding towards zero
Floor(): Int Rounding towards negative infinity
HalfDown(): Int Rounding down towards the nearest integer
HalfEven(): Int Rounding towards the nearest even integer
HalfUp(): Int Rounding up towards the nearest integer
Up(): Int Rounding away from zero

Examples

-1.6 -1.5 -1.4 -1.0 1.0 1.4 1.5 1.6
Ceiling -1 -1 -1 -1 1 2 2 2
Down -1 -1 -1 -1 1 1 1 1
Floor -2 -2 -2 -1 1 1 1 1
HalfDown -2 -1 -1 -1 1 1 1 2
HalfEven -2 -2 -1 -1 1 1 2 2
HalfUp -2 -2 -1 -1 1 1 2 2
Up -2 -2 -2 -1 1 2 2 2

results matching ""

    No results matching ""