Skip to main content
Use the pi function in APL to return the mathematical constant π (pi), approximately equal to 3.14159265358979. The function takes no arguments and always returns the same double-precision floating-point value. pi is most commonly used to construct radian angle values for trigonometric functions. For example, you can encode the hour of day as a cyclic coordinate using (hour * 2 * pi()) / 24, or convert between degrees and radians using radians = degrees * pi() / 180.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, pi() returns the same constant and works identically.
| eval angle = 2 * pi()
In ANSI SQL, PI() is a standard function in SQL Server and PostgreSQL that returns π.
SELECT PI() AS pi_value

Usage

Syntax

pi()

Parameters

None.

Returns

The double-precision value of π: approximately 3.14159265358979.

Example

Use pi to encode the hour of day as a cyclic angle for time-based analysis. Query
['sample-http-logs']
| extend hour_angle = (hourofday(_time) * 2 * pi()) / 24
| extend sin_hour = sin(hour_angle)
| extend cos_hour = cos(hour_angle)
| project _time, id, sin_hour, cos_hour
Run in Playground Output
_timeidsin_hourcos_hour
2024-11-14 00:00:00user-10.00001.0000
2024-11-14 06:00:00user-21.00000.0000
2024-11-14 12:00:00user-30.0000-1.0000
  • sin: Returns the sine of an angle in radians. Combine with pi to encode cyclic signals.
  • cos: Returns the cosine of an angle in radians. Use together with sin and pi for cyclic coordinate encoding.
  • radians: Converts degrees to radians. Use it as an alternative to manually multiplying by pi() / 180.
  • degrees: Converts radians to degrees. Use it to express results from inverse trig functions in degrees instead of radians.
  • atan2: Returns the angle in radians between two coordinates. Its output range is (-π, π], so pi is a natural companion.