xur-std 0.1.7

The standard library of the Xur language
Documentation
//! Methods of integers and floats.

use xur_runtime::{BuiltinType, Registry};

pub(crate) fn register(registry: &Registry) {
    registry
        .builtin(BuiltinType::Int)
        .named_function("abs", &["x"], |x: i64| x.abs())
        .named_function("pow", &["x", "exp"], |x: i64, exp: u32| x.pow(exp))
        .named_function("min", &["x", "y"], |x: i64, y: i64| x.min(y))
        .named_function("max", &["x", "y"], |x: i64, y: i64| x.max(y))
        .named_function("to_float", &["x"], |x: i64| x as f64)
        .named_function("to_string", &["x"], |x: i64| x.to_string())
        .named_function("to_hex", &["x"], |x: i64| format!("{x:x}"));
    registry
        .builtin(BuiltinType::Float)
        .named_function("abs", &["x"], |x: f64| x.abs())
        .named_function("sqrt", &["x"], |x: f64| x.sqrt())
        .named_function("floor", &["x"], |x: f64| x.floor())
        .named_function("ceil", &["x"], |x: f64| x.ceil())
        .named_function("round", &["x"], |x: f64| x.round())
        .named_function("to_int", &["x"], |x: f64| x as i64)
        .named_function("to_string", &["x"], |x: f64| x.to_string());
}