Skip to main content

reifydb_function/math/scalar/
euler.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use std::f64::consts::E;
5
6use reifydb_core::value::column::data::ColumnData;
7use reifydb_type::value::r#type::Type;
8
9use crate::{
10	ScalarFunction, ScalarFunctionContext,
11	error::{ScalarFunctionError, ScalarFunctionResult},
12	propagate_options,
13};
14
15pub struct Euler;
16
17impl Euler {
18	pub fn new() -> Self {
19		Self
20	}
21}
22
23impl ScalarFunction for Euler {
24	fn scalar(&self, ctx: ScalarFunctionContext) -> ScalarFunctionResult<ColumnData> {
25		if let Some(result) = propagate_options(self, &ctx) {
26			return result;
27		}
28		if !ctx.columns.is_empty() {
29			return Err(ScalarFunctionError::ArityMismatch {
30				function: ctx.fragment.clone(),
31				expected: 0,
32				actual: ctx.columns.len(),
33			});
34		}
35
36		Ok(ColumnData::float8_with_bitvec(vec![E], vec![true]))
37	}
38
39	fn return_type(&self, _input_types: &[Type]) -> Type {
40		Type::Float8
41	}
42}