Polyfiill some functions for decimal+no_float.

This commit is contained in:
Stephen Chung
2021-08-11 16:09:04 +08:00
parent 73c0ba4ec5
commit e0cae4546c
2 changed files with 26 additions and 1 deletions

View File

@@ -309,6 +309,22 @@ mod decimal_functions {
Decimal, MathematicalOps,
};
#[cfg(feature = "no_float")]
pub mod float_polyfills {
#[rhai_fn(name = "PI")]
pub fn pi() -> Decimal {
Decimal::PI
}
#[rhai_fn(name = "E")]
pub fn e() -> Decimal {
Decimal::E
}
#[rhai_fn(return_raw)]
pub fn parse_float(s: &str) -> Result<Decimal, Box<EvalAltResult>> {
super::parse_decimal(s)
}
}
#[rhai_fn(return_raw)]
pub fn sqrt(x: Decimal) -> Result<Decimal, Box<EvalAltResult>> {
x.sqrt()