Skip to main content

rl_lang/interpreter/stdlib/math/
log2.rs

1use crate::{
2    interpreter::{evaluator::Evaluator, values::Value},
3    utils::{errors::Error, span::Span},
4};
5
6pub fn std_log2(eval: &mut Evaluator, a: Value, span: Span) -> Result<Value, Error> {
7    match a {
8        Value::Integer(i) => Ok(Value::Float((i as f64).log2())),
9        Value::Float(f) => Ok(Value::Float(f.log2())),
10        other => Err(eval.err(
11            format!("log2() expects a number, got {}", other.type_name()),
12            span,
13        )),
14    }
15}