cos
cos is useful in observability and log analysis when you need to encode time-of-day or other cyclic patterns as a continuous numeric feature. For example, you can combine cos and sin to represent hour-of-day as a pair of cyclic coordinates, which preserves the circular distance between hours for anomaly detection or grouping.
Usage#
Syntax#
cos(x)Parameters#
| Name | Type | Required | Description |
|---|---|---|---|
x |
real | Yes | The angle in radians. |
Returns#
The cosine of x, a real number in the range [-1, 1].
Example#
Use cos to compute the cosine of an angle in radians.
Query
print result = cos(pi())Output
| result |
|---|
| -1 |
List of related functions#
- sin: Returns the sine. Use
sinandcostogether to produce a two-dimensional cyclic encoding of angles. - tan: Returns the tangent. Use it when you need the ratio of sine to cosine.
- acos: Returns the arc cosine. Use it as the inverse of
cos. - pi: Returns the constant π. Use it to compute angle values in radians.
- radians: Converts degrees to radians. Use it to prepare angle inputs before calling
cos.
Other query languages#
Splunk SPL users
In Splunk SPL, cos() is available in the eval command with the same behavior: it takes an angle in radians and returns the cosine.
Splunk example
| eval cos_val = cos(angle_rad)APL equivalent
['sample-http-logs']
| extend cos_val = cos(angle_rad)ANSI SQL users
In ANSI SQL, COS() is a standard mathematical function with identical semantics.
SQL example
SELECT COS(angle_rad) AS cos_val FROM logsAPL equivalent
['sample-http-logs']
| extend cos_val = cos(angle_rad)