use bigdecimal::{BigDecimal, ToPrimitive};
use crate::value::Value;
mod arith;
mod bits;
mod compare;
mod index;
#[cfg(test)]
mod tests;
pub use arith::{add, div, floordiv, mul, neg, not_, pow, rem, sub};
pub use bits::{bitand, bitnot, bitor, bitxor, shl, shr};
pub use compare::{eq, ge, gt, in_, le, lt, ne, not_in, values_equal};
pub(crate) use compare::{order, slice_contains};
pub use index::{index_get, index_set, iter_value, slice_get, unpack_value};
pub(super) fn as_f64(v: &Value) -> Option<f64> {
match v {
Value::Int(n) => n.to_f64(),
Value::Float(f) => Some(*f),
_ => None,
}
}
pub(super) fn as_decimal(v: &Value) -> Option<BigDecimal> {
match v {
Value::Int(n) => Some(BigDecimal::from(n.clone())),
Value::Decimal(d) => Some(d.clone()),
_ => None,
}
}
pub(super) fn is_decimal(v: &Value) -> bool {
matches!(v, Value::Decimal(_))
}
pub(super) fn is_float(v: &Value) -> bool {
matches!(v, Value::Float(_))
}