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