# SQL Server Mathematical Functions-1

SQL Server’s mathematical functions assist in calculating values. The functions will assist with fundamental addition, subtraction, multiplication, and division, among other things. Let’s take a look at each one with an example.

Mathematical Functions:

• ABS(x)
This function returns the absolute value of X.
Example: SELECT ABS(-19.99)
Result: 19.99
• ACOS(x)
This function accepts a Cos value as the input and returns the angle in radians.
An expression of either type float or of a type that can implicitly convert to float.
Only a value ranging from -1.00 to 1.00 is valid. For values outside this range, no value is returned, and ACOS will report a domain error.
Example: SELECT ACOS(0)
Result: 1.5707963267949

• ASIN(x)
This function accepts a Sin value as the input and returns the angle in radians.
An expression of either type float or of a type that can implicitly convert to float.
Only a value ranging from -1.00 to 1.00 is valid. For values outside this range, no value is returned, and ASIN will report a domain error.
Example:  SELECT ASIN(1)
Result: 1.5707963267949

• ATAN(x)
This function accepts a Tan value as the input and returns the angle in radians.
An expression of either type float or of a type that implicitly convert to float.
Example : SELECT ATAN(1)
Result: 0.785398163397448

• ATN2(x,y)
Returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified float expressions.
Example: SELECT ATN2(45.12,1.2)
Result: 1.54420685014236

• CEILING(x)
This returns the largest integer value that is either less than X or equal to it.
Example: SELECT CEILING(6.8)
Result: 7

• COS(x)
This function accepts an angle in radians as its parameter and returns its Cosine value.
A mathematical function that returns the trigonometric cosine of the specified angle – measured in radians – in the specified expression.
Example: SELECT COS(0)
Result: 1

• COT(x)
This function returns the trigonometric cotangent of the specified angle – in radians – in the specified float expression.
A mathematical function that returns the trigonometric cotangent of the specified angle – in radians – in the specified float expression.
Example: SELECT COT(124.1332)
Result: -0.0403119983711489

• DEGREES(expr)
This function returns the corresponding angle, in degrees, for an angle specified in radians.
Example: SELECT DEGREES((PI()/2))
Result: 90

• EXP(x)
Returns the exponential value of the specified float expression.
The constant e (2.718281…), is the base of natural logarithms.
The exponent of a number is the constant e raised to the power of the number. For example EXP(1.0) = e^1.0 = 2.71828182845905 and EXP(10) = e^10 = 22026.4657948067.
The exponential of the natural logarithm of a number is the number itself: EXP (LOG (n)) = n.
And the natural logarithm of the exponential of a number is the number itself: LOG (EXP (n)) = n.
Example: SELECT EXP(2)
Result: 7.38905609893065

• FLOOR(x)
This returns the smallest integer value that is either more than X or equal to it.
Example: SELECT FLOOR(6.8)
Result: 6

• LOG(x)
Returns the natural logarithm of the specified float expression in SQL Server.
By default, LOG() returns the natural logarithm. Starting with SQL Server 2012 (11.x), you can change the base of the logarithm to another value by using the optional base parameter.
The natural logarithm is the logarithm to the base e, where e is an irrational constant approximately equal to 2.718281828.
The natural logarithm of the exponential of a number is the number itself: LOG( EXP( n ) ) = n. And the exponential of the natural logarithm of a number is the number itself: EXP( LOG( n ) ) = n.
Example: SELECT LOG(10)
Result: 2.30258509299405

• LOG10(x)
Returns the base-10 logarithm of the specified float expression.
The LOG10 and POWER functions are inversely related to one another. For example, 10 ^ LOG10(n) = n.
Example: SELECT LOG10(145.175643)
Result: 2.16189375825097

• PI()
Returns the constant value of PI.
Example: SELECT PI()
Result: 3.14159265358979