Skip to main content

cos

1. COS Function

The COS function in H2 database is used to calculate the cosine of a given angle in radians.

2. Syntax

The syntax for the COS function in H2 database is as follows:

COS(angle)

Arguments

  • angle: The angle for which the cosine needs to be calculated. It should be a numeric value representing the angle in radians.

Return

  • The COS function returns the cosine of the given angle.

3. Notes

  • The COS function in H2 database expects the angle to be in radians. If the angle is in degrees, you can convert it to radians using the RADIANS function.
  • If the input angle is not a number or exceeds the numeric range, the COS function will return NULL.
  • Ensure that you use the correct syntax and datatype while using the COS function to avoid errors.

4. Examples

Here are a few examples demonstrating the usage of the COS function in H2 database:

Example 1 - Calculating the cosine of 1 radian:

SELECT COS(1) AS cosine;

Output:

cosine
-------
0.5403023058681398

Example 2 - Calculating the cosine of an angle stored in a column:

CREATE TABLE angles (
id INT PRIMARY KEY,
angle DOUBLE
);

INSERT INTO angles VALUES (1, 0.5), (2, 1), (3, 1.5);

SELECT id, angle, COS(angle) AS cosine
FROM angles;

Output:

id | angle |        cosine
---+-------+---------------------
1 | 0.5 | 0.8775825618903728
2 | 1 | 0.5403023058681398
3 | 1.5 | 0.0707372016677029
  • sin - Calculate sine
  • tan - Calculate tangent