Skip to main content

graphrecords_query/capabilities/numeric/
exponential.rs

1use crate::{
2    Failure, IndexValue, QueryResult, Scalar, ValueDomain, error::numeric::NonNumericValue,
3};
4use graphrecords_core::graphrecord::GraphRecordValue;
5
6pub trait ValueExponential: ValueDomain {
7    fn exponential<'a>(label: &'static str, value: Self::Value<'a>)
8    -> QueryResult<Self::Value<'a>>;
9}
10
11impl ValueExponential for Scalar {
12    fn exponential<'a>(
13        label: &'static str,
14        value: Self::Value<'a>,
15    ) -> QueryResult<Self::Value<'a>> {
16        match value {
17            GraphRecordValue::Int(integer) => Ok(GraphRecordValue::Float((integer as f64).exp())),
18            GraphRecordValue::Float(float) => Ok(GraphRecordValue::Float(float.exp())),
19            value => Err(Failure::new(label, NonNumericValue::new(value))),
20        }
21    }
22}
23
24impl ValueExponential for IndexValue<GraphRecordValue> {
25    fn exponential<'a>(
26        label: &'static str,
27        value: Self::Value<'a>,
28    ) -> QueryResult<Self::Value<'a>> {
29        match value {
30            GraphRecordValue::Int(integer) => Ok(GraphRecordValue::Float((integer as f64).exp())),
31            GraphRecordValue::Float(float) => Ok(GraphRecordValue::Float(float.exp())),
32            value => Err(Failure::new(label, NonNumericValue::new(value))),
33        }
34    }
35}