In MariaDB, COS()
is a built-in numeric function that returns the cosine of its argument, where the argument is provided in radians.
Syntax
The syntax goes like this:
COS(X)
Where X
is the number, provided in radians.
Example
Here’s an example:
SELECT COS(3);
Result:
+---------------------+ | COS(3) | +---------------------+ | -0.9899924966004454 | +---------------------+
Here’s what happens when we provide π (pi):
SELECT
PI(),
COS(PI());
Result:
+----------+-----------+ | PI() | COS(PI()) | +----------+-----------+ | 3.141593 | -1 | +----------+-----------+
Non-Numeric Arguments
Here’s an example of what happens when we provide a non-numeric argument:
SELECT COS('Cat');
Result:
+------------+ | COS('Cat') | +------------+ | 1 | +------------+ 1 row in set, 1 warning (0.010 sec)
Let’s check the warning:
SHOW WARNINGS;
Result:
+---------+------+-----------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Cat' | +---------+------+-----------------------------------------+
Null Arguments
COS()
returns null
if the argument is null
:
SELECT COS(null);
Result:
+-----------+ | COS(null) | +-----------+ | NULL | +-----------+
Missing Arguments
Calling COS()
with the wrong number of arguments, or without any arguments results in an error:
SELECT COS();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'COS'
And:
SELECT COS(10, 2);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'COS'