reifydb_routine/function/math/
pi.rs1use std::f64::consts::PI;
5
6use reifydb_core::value::column::{Column, columns::Columns, data::ColumnData};
7use reifydb_type::value::r#type::Type;
8
9use crate::function::{Function, FunctionCapability, FunctionContext, FunctionInfo, error::FunctionError};
10
11pub struct Pi {
12 info: FunctionInfo,
13}
14
15impl Default for Pi {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl Pi {
22 pub fn new() -> Self {
23 Self {
24 info: FunctionInfo::new("math::pi"),
25 }
26 }
27}
28
29impl Function for Pi {
30 fn info(&self) -> &FunctionInfo {
31 &self.info
32 }
33
34 fn capabilities(&self) -> &[FunctionCapability] {
35 &[FunctionCapability::Scalar]
36 }
37
38 fn return_type(&self, _input_types: &[Type]) -> Type {
39 Type::Float8
40 }
41
42 fn execute(&self, ctx: &FunctionContext, args: &Columns) -> Result<Columns, FunctionError> {
43 if !args.is_empty() {
44 return Err(FunctionError::ArityMismatch {
45 function: ctx.fragment.clone(),
46 expected: 0,
47 actual: args.len(),
48 });
49 }
50
51 Ok(Columns::new(vec![Column::new(ctx.fragment.clone(), ColumnData::float8(vec![PI]))]))
52 }
53}