Math functions

These functions helps you to perform complex math operations like square root, cube root, logarithm, etc. with great ease.

SRON provides 13 major math functions given below:

  • abs()

  • cbrt()

  • ceil()

  • cos()

  • floor()

  • log()

  • log2()

  • log10()

  • max()

  • min()

  • sin()

  • sqrt()

  • tan()


1. abs() :

Returns the absolute value of a number, disregarding its sign, making negative numbers positive.

{
    name : MAIN
    Double val = abs(-153.2356)
    println(val)

    val = abs(-67)
    println(val)
}

OUTPUT:

153.2356 67


2. cbrt() :

Computes the cube root of a number, finding the value that, when multiplied by itself twice, equals the original number.

{
    name : MAIN
    Int val = cbrt(64)
    println(val)
}

OUTPUT:

4


3. ceil() :

Rounds a number up to the nearest integer, returning the smallest integer greater than or equal to the input.

{
    name : MAIN
    Double val = ceil(153.234)
    println(val)

    val = ceil(122.6)
    println(val)
}

OUTPUT:

154 123


4. cos() :

Calculates the cosine of an angle given in radians, representing the ratio of the adjacent side to the hypotenuse in a right triangle.

{
    name : MAIN
    Double val = cos(135)
    println(val)
}

OUTPUT:

-0.996088


5. floor() :

Rounds a number down to the nearest integer, returning the largest integer less than or equal to the input.

{
    name : MAIN
    Int val = floor(123.673)
    println(val)

    val = floor(63.213)
    println(val)
}

OUTPUT:

123 63


6. log() :

Computes the natural logarithm of a number, representing the power to which the base 'e' (approximately 2.718) must be raised to equal the input.

{
    name : MAIN
    Double val = log(55)
    println(val)
}

OUTPUT:

4.00733


7. log2() :

Calculates the base-2 logarithm of a number, determining the exponent to which the base 2 must be raised to produce the input.

{
    name : MAIN
    Double val = log2(55)
    println(val)
}

OUTPUT:

5.78136


8. log10() :

Computes the base-10 logarithm of a number, indicating the exponent to which the base 10 must be raised to yield the input.

{
    name : MAIN
    Double val = log10(55)
    println(val)
}

OUTPUT:

1.74036


9. max() :

Returns the maximum value from a sequence of numbers or values, identifying the largest element.

{
    name : MAIN
    Int val = max(1,2,3,6,100,-145,77)
    println(val)
}

OUTPUT:

100


10. min() :

Retrieves the minimum value from a series of numbers or values, identifying the smallest element.

{
    name : MAIN
    Int val = min(1,2,3,6,100,-145,77)
    println(val)
}

OUTPUT:

-145


11. sin() :

Computes the sine of an angle in radians, representing the ratio of the length of the side opposite the angle to the length of the hypotenuse in a right triangle.

{
    name : MAIN
    Double val = sin(45)
    println(val)
}

OUTPUT:

0.850904


12. sqrt() :

Calculates the square root of a number, determining the value that, when multiplied by itself, equals the input.

{
    name : MAIN
    Double val = sqrt(256)
    println(val)
}

OUTPUT:

16


13. tan() :

Computes the tangent of an angle given in radians, representing the ratio of the length of the side opposite the angle to the length of the adjacent side in a right triangle.

{
    name : MAIN
    Double val = tan(75)
    println(val)
}

OUTPUT:

-0.420701


Last updated