Add new floating-point functions.
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user