Add f32_float feature.
This commit is contained in:
@@ -224,25 +224,32 @@ gen_signed_functions!(signed_num_128 => i128);
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod f32_functions {
|
||||
#[rhai_fn(name = "+")]
|
||||
pub fn add(x: f32, y: f32) -> f32 {
|
||||
x + y
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
pub fn subtract(x: f32, y: f32) -> f32 {
|
||||
x - y
|
||||
}
|
||||
#[rhai_fn(name = "*")]
|
||||
pub fn multiply(x: f32, y: f32) -> f32 {
|
||||
x * y
|
||||
}
|
||||
#[rhai_fn(name = "/")]
|
||||
pub fn divide(x: f32, y: f32) -> f32 {
|
||||
x / y
|
||||
}
|
||||
#[rhai_fn(name = "%")]
|
||||
pub fn modulo(x: f32, y: f32) -> f32 {
|
||||
x % y
|
||||
#[cfg(not(feature = "f32_float"))]
|
||||
pub mod basic_arithmetic {
|
||||
#[rhai_fn(name = "+")]
|
||||
pub fn add(x: f32, y: f32) -> f32 {
|
||||
x + y
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
pub fn subtract(x: f32, y: f32) -> f32 {
|
||||
x - y
|
||||
}
|
||||
#[rhai_fn(name = "*")]
|
||||
pub fn multiply(x: f32, y: f32) -> f32 {
|
||||
x * y
|
||||
}
|
||||
#[rhai_fn(name = "/")]
|
||||
pub fn divide(x: f32, y: f32) -> f32 {
|
||||
x / y
|
||||
}
|
||||
#[rhai_fn(name = "%")]
|
||||
pub fn modulo(x: f32, y: f32) -> f32 {
|
||||
x % y
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
pub fn pow_f_f(x: f32, y: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(Dynamic::from(x.powf(y)))
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
pub fn neg(x: f32) -> f32 {
|
||||
@@ -261,10 +268,6 @@ mod f32_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
pub fn pow_f_f(x: f32, y: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(Dynamic::from(x.powf(y)))
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
pub fn pow_f_i(x: f32, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && y > (i32::MAX as INT) {
|
||||
Err(make_err(format!(
|
||||
@@ -280,6 +283,33 @@ mod f32_functions {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod f64_functions {
|
||||
#[cfg(feature = "f32_float")]
|
||||
pub mod basic_arithmetic {
|
||||
#[rhai_fn(name = "+")]
|
||||
pub fn add(x: f64, y: f64) -> f64 {
|
||||
x + y
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
pub fn subtract(x: f64, y: f64) -> f64 {
|
||||
x - y
|
||||
}
|
||||
#[rhai_fn(name = "*")]
|
||||
pub fn multiply(x: f64, y: f64) -> f64 {
|
||||
x * y
|
||||
}
|
||||
#[rhai_fn(name = "/")]
|
||||
pub fn divide(x: f64, y: f64) -> f64 {
|
||||
x / y
|
||||
}
|
||||
#[rhai_fn(name = "%")]
|
||||
pub fn modulo(x: f64, y: f64) -> f64 {
|
||||
x % y
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
pub fn pow_f_f(x: f64, y: f64) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(Dynamic::from(x.powf(y)))
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
pub fn neg(x: f64) -> f64 {
|
||||
-x
|
||||
|
@@ -215,10 +215,6 @@ mod float_functions {
|
||||
Ok((x.trunc() as INT).into())
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "to_float")]
|
||||
pub fn f32_to_float(x: f32) -> FLOAT {
|
||||
x as FLOAT
|
||||
}
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
pub fn f64_to_int(x: f64) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {
|
||||
@@ -244,6 +240,13 @@ mod float_functions {
|
||||
.into()
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "f32_float"))]
|
||||
pub mod f32_f64 {
|
||||
#[rhai_fn(name = "to_float")]
|
||||
pub fn f32_to_f64(x: f32) -> f64 {
|
||||
x as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
|
Reference in New Issue
Block a user