This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

# Module : math

## Module Overview

This module provides functions to perform fixed-precision integer arithmetic and fixed-precision decimal arithmetic. It includes functions to get the absolute, cosine, sine, root, tangent, and more for a given value.

For information on the operation, which you can perform with this module, see the below Function. For examples on the usage of the operation, see Math Api.

 Detail Record type to hold the details of an error.
 absFloat Calculates the absolute value of a float value. absInt Calculates the absolute value of an int value. acos Calculates the arc cosine of a value; the returned angle is in the range 0. asin Calculates the arc sine of a value. atan Calculates the arc tangent of a value. atan2 Calculates the angle theta from the conversion of rectangular coordinates (a, b) to polar coordinates (r, theta). cbrt Calculates the cube root of a float value. ceil Calculates the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. copySign Calculates the first floating-point argument with the sign of the second floating-point argument. cos Calculates the trigonometric cosine of an angle. cosh Calculates the hyperbolic cosine of a float value. exp Calculates Euler's number, that is 'e' raised to the power of exponent. expm1 Calculates (e to the power of x) -1. floor Calculates the largest (closest to positive infinity) float value that is less than or equal to the argument and is equal to a mathematical integer. floorDiv Calculates the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient. floorMod Calculates the floor modulus of the long arguments. getExponent Calculates the unbiased exponent used in the representation of a float. hypot Calculates sqrt(a squared +b squared) without intermediate overflow or underflow. log Calculates the natural logarithm (base e) of a float value. log10 Calculates the base 10 logarithm of a float value. log1p Calculates the natural logarithm of the sum of the argument and 1. negateExact Calculates the negation of the argument. nextAfter Calculates the floating-point number adjacent to the first argument in the direction of the second argument. nextDown Calculates the adjacent floating-point value closer to negative infinity. nextUp Calculates the adjacent floating-point value closer to positive infinity. pow Calculates the value of the 'a' raised to the power of 'b'. random Selects a random number between 0. randomInRange Selects a random number between the given start(inclusive) and end(exclusive) values. remainder Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. rint Calculates the double value that is closest in value to the argument and is equal to a mathematical integer. round Calculates the closest int to the argument, with ties rounding to positive infinity. scalb Calculates a × (2 to the power of b) rounded as if performed by a single correctly rounded floating-point multiply to a member of the float value set. signum Calculates the signum function of the argument. sin Calculates the trigonometric sine of an angle. sinh Calculates the hyperbolic sine of a float value. sqrt Calculates rounded positive square root of the given value. tan Calculates the trigonometric tangent of an angle. tanh Calculates the hyperbolic tangent of a double value. toDegrees Converts an angle measured in radians to an approximately equivalent angle measured in degrees. toRadians Converts an angle measured in degrees to an approximately equivalent angle measured in radians. ulp Returns the size of an ulp of the argument.
 ARITHMETIC_ERROR Represents the reason string for the `math:Error`. PI Ratio of the circumference of a circle to its diameter. E Base of the natural logarithms.
 Error Represents an error occurred in the `math` operation.