How the PI() function works in Mariadb?

The PI() function is a built-in function in Mariadb that returns the value of the mathematical constant pi, which is approximately 3.14159.

Posted on

The PI() function is a built-in function in Mariadb that returns the value of the mathematical constant pi, which is approximately 3.14159. The function is useful for performing calculations involving circles, angles, trigonometry, and other fields of mathematics. The function is also known as PI.

Syntax

The syntax of the PI() function is as follows:

PI()

The function does not take any arguments. The function returns a decimal value that is the value of pi.

Examples

Example 1: Getting the value of pi with the PI() function

The following example shows how to use the PI() function to get the value of pi:

SELECT PI() AS Pi;

The output is:

+----------+
| Pi       |
+----------+
| 3.141593 |
+----------+

The function returns the value of pi, which is 3.14159265358979.

Example 2: Calculating the area of a circle with the PI() function

The following example shows how to use the PI() function to calculate the area of a circle with a given radius:

SELECT PI() * POWER(5, 2) AS Area;

The output is:

+-------------------+
| Area              |
+-------------------+
| 78.53981633974483 |
+-------------------+

The function returns the area of a circle with a radius of 5, which is 78.5398. The formula for the area of a circle is $$\pi r^2$$, where $$r$$ is the radius.

Example 3: Calculating the circumference of a circle with the PI() function

The following example shows how to use the PI() function to calculate the circumference of a circle with a given radius:

SELECT 2 * PI() * 5 AS Circumference;

The output is:

+---------------+
| Circumference |
+---------------+
|     31.415927 |
+---------------+

The function returns the circumference of a circle with a radius of 5, which is 31.4159. The formula for the circumference of a circle is $$2\pi r$$, where $$r$$ is the radius.

There are some other functions in Mariadb that are related to the PI() function. They are:

  • SIN(): This function returns the sine of a given angle in radians. The function is useful for calculating the ratio of the opposite side to the hypotenuse of a right triangle. The function is also known as SINE().
  • COS(): This function returns the cosine of a given angle in radians. The function is useful for calculating the ratio of the adjacent side to the hypotenuse of a right triangle. The function is also known as COSINE().
  • TAN(): This function returns the tangent of a given angle in radians. The function is useful for calculating the ratio of the opposite side to the adjacent side of a right triangle. The function is also known as TANGENT().

Conclusion

The PI() function is a useful function in Mariadb that allows you to get the value of the mathematical constant pi, which is approximately 3.14159. The function is helpful for performing calculations involving circles, angles, trigonometry, and other fields of mathematics. You can also use other functions like SIN(), COS(), and TAN() to perform trigonometric operations with the value of pi. I hope this article helped you understand how the PI() function works in Mariadb.