# Azure Cosmos DB for NoSQL: ABS, EXP, and SIN Functions with Examples

In the dynamic landscape of data management and analysis, businesses require powerful tools to perform mathematical operations on their data effectively. Azure Cosmos DB, Microsoft’s globally distributed, multi-model NoSQL database service, offers a comprehensive set of mathematical functions to handle complex numerical computations. In this blog post, we will focus on three essential mathematical functions provided by Azure Cosmos DB’s SQL API: ABS, EXP, and SIN. We will explore the usage of each function through illustrative examples.

## Understanding ABS, EXP, and SIN Functions

Before diving into the examples, let’s briefly understand each of the functions:

**ABS**: The ABS function calculates the absolute value of a given numerical expression. It returns the positive magnitude of the value, discarding its sign.**EXP**: The EXP function calculates the exponential value of a given numerical expression. It returns e raised to the power of the specified value, where e is the base of the natural logarithm (approximately equal to 2.71828).**SIN**: The SIN function calculates the sine value of a given numerical expression. It returns the sine of the specified angle, where the input angle is in radians.

## Sample Data

To demonstrate the ABS, EXP, and SIN functions, let’s consider a container called “trigonometry” in our Azure Cosmos DB database. We will create documents representing angles in degrees, and each document will look like this:

1 2 3 4 |
{ "angleId": "1", "angleInDegrees": 45 } |

## ABS Function Example

Suppose we want to calculate the absolute value of the difference between two angles, `angleA`

and `angleB`

. We can use the ABS function as follows:

1 2 |
SELECT angleA, angleB, ABS(angleA - angleB) AS absoluteDifference FROM trigonometry |

In this query, `ABS(angleA - angleB)`

calculates the absolute value of the difference between `angleA`

and `angleB`

. The result will provide the angles `angleA`

and `angleB`

along with the absolute difference between them.

## EXP Function Example

Let’s explore an example where we need to calculate the exponential value of an angle in degrees. We can use the EXP function as follows:

1 2 |
SELECT angleInDegrees, EXP(angleInDegrees) AS exponentialValue FROM trigonometry |

In this query, `EXP(angleInDegrees)`

calculates the exponential value of the angle specified in degrees. The result will provide the original angle in degrees along with its corresponding exponential value.

## SIN Function Example

Suppose we want to calculate the sine value of each angle in degrees. We can use the SIN function as follows:

1 2 |
SELECT angleInDegrees, SIN(RADIANS(angleInDegrees)) AS sineValue FROM trigonometry |

In this query, `SIN(RADIANS(angleInDegrees))`

calculates the sine value of the angle specified in degrees. The `RADIANS(angleInDegrees)`

expression converts the angle from degrees to radians before applying the SIN function. The result will provide the original angle in degrees along with its corresponding sine value.

## Conclusion

In this blog post, we explored three essential mathematical functions provided by Azure Cosmos DB’s SQL API: ABS, EXP, and SIN. These functions empower developers and businesses to perform various numerical calculations and derive valuable insights from their data.

Whether it’s calculating absolute differences, obtaining exponential values, or finding sine values, Azure Cosmos DB’s mathematical functions provide the flexibility and computational power to handle complex numerical operations seamlessly.

By leveraging the capabilities of Azure Cosmos DB and its mathematical functions, businesses can build data-driven applications that analyze data with precision, gain deeper insights, and make well-informed decisions.

So, embrace the potential of Azure Cosmos DB’s mathematical functions and unlock the true value of your numerical data to drive your business forward.

Happy computing!