The ACOS()
function in SQLite is used to calculate the arc cosine (inverse cosine) of a given numeric value. The result is the angle in radians whose cosine is the specified number.
Syntax
ACOS(X)
Where X
is the numeric value for which you want to calculate the arc cosine. It must be in the range -1 to 1 because these are the only values for which cosine values are defined.
The result will be an angle in radians between 0 and π (3.14159…).
Example 1
Here’s a quick example to demonstrate how it works:
SELECT ACOS(0.32);
Output:
1.24506683950027
Example 2
Suppose we have a table angles
with a column cos_value
that contains cosine values, and we want to find the corresponding angle in radians for these values.
CREATE TABLE angles (cos_value REAL);
INSERT INTO angles (cos_value) VALUES (1), (0.5), (0), (-0.5), (-1);
Now, we can use ACOS()
to calculate the angles for each cosine value:
SELECT cos_value, ACOS(cos_value) AS angle_in_radians
FROM angles;
Output:
cos_value angle_in_radians
--------- ----------------
1.0 0.0
0.5 1.0471975511966
0.0 1.5707963267949
-0.5 2.0943951023932
-1.0 3.14159265358979
In this example:
- When
cos_value
is1
, the angle is0
radians (cosine of 0 radians is 1). - When
cos_value
is0.5
, the angle is approximately1.0471975511966
radians. - When
cos_value
is0
, the angle is approximately1.5707963267949
radians (π/2), as the cosine of π/2 is 0. - Similarly,
-1
corresponds to π radians, or approximately3.14159265358979
.