Add new floating-point functions.

This commit is contained in:
Stephen Chung
2021-02-09 15:57:38 +08:00
parent 4815de3634
commit 8f47f7c9e2
2 changed files with 21 additions and 0 deletions

View File

@@ -154,6 +154,26 @@ mod trig_functions {
mod float_functions {
use crate::FLOAT;
#[rhai_fn(name = "E")]
pub fn e() -> FLOAT {
#[cfg(not(feature = "f32_float"))]
return crate::stdlib::f64::consts::E;
#[cfg(feature = "f32_float")]
return crate::stdlib::f32::consts::E;
}
#[rhai_fn(name = "PI")]
pub fn pi() -> FLOAT {
#[cfg(not(feature = "f32_float"))]
return crate::stdlib::f64::consts::PI;
#[cfg(feature = "f32_float")]
return crate::stdlib::f32::consts::PI;
}
pub fn to_radians(x: FLOAT) -> FLOAT {
x.to_radians()
}
pub fn to_degrees(x: FLOAT) -> FLOAT {
x.to_degrees()
}
pub fn sqrt(x: FLOAT) -> FLOAT {
x.sqrt()
}