grass/src/builtin/math.rs

16 lines
524 B
Rust
Raw Normal View History

use std::collections::BTreeMap;
2020-02-02 21:09:29 -05:00
use super::Builtin;
use crate::units::Unit;
use crate::value::{Number, Value};
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
decl!(f "percentage", |args, _| {
let arg = dbg!(arg!(args, 0, "number").eval());
let num = match arg {
Value::Dimension(n, Unit::None) => n * Number::from(100),
_ => todo!("expected unitless number in builtin function `percentage()`")
};
Some(Value::Dimension(num, Unit::Percent))
});
}