Fix doc comment links.
This commit is contained in:
parent
fa41f4faf0
commit
90200e607c
@ -36,9 +36,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -81,7 +81,7 @@ impl Engine {
|
|||||||
/// Modules referred by `import` statements containing literal string paths are eagerly resolved
|
/// Modules referred by `import` statements containing literal string paths are eagerly resolved
|
||||||
/// via the current [module resolver][crate::ModuleResolver] and embedded into the resultant
|
/// via the current [module resolver][crate::ModuleResolver] and embedded into the resultant
|
||||||
/// [`AST`]. When it is evaluated later, `import` statement directly recall pre-resolved
|
/// [`AST`]. When it is evaluated later, `import` statement directly recall pre-resolved
|
||||||
/// [modules][Module] and the resolution process is not performed again.
|
/// [modules][crate::Module] and the resolution process is not performed again.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
pub fn compile_into_self_contained(
|
pub fn compile_into_self_contained(
|
||||||
&self,
|
&self,
|
||||||
@ -146,22 +146,22 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(ast)
|
Ok(ast)
|
||||||
}
|
}
|
||||||
/// When passed a list of strings, first join the strings into one large script,
|
/// When passed a list of strings, first join the strings into one large script, and then
|
||||||
/// and then compile them into an [`AST`] using own scope, which can be used later for evaluation.
|
/// compile them into an [`AST`] using own scope, which can be used later for evaluation.
|
||||||
///
|
///
|
||||||
/// The scope is useful for passing constants into the script for optimization
|
/// The scope is useful for passing constants into the script for optimization when using
|
||||||
/// when using [`OptimizationLevel::Full`].
|
/// [`OptimizationLevel::Full`][crate::OptimizationLevel::Full].
|
||||||
///
|
///
|
||||||
/// ## Note
|
/// ## Note
|
||||||
///
|
///
|
||||||
/// All strings are simply parsed one after another with nothing inserted in between, not even
|
/// All strings are simply parsed one after another with nothing inserted in between, not even a
|
||||||
/// a newline or space.
|
/// newline or space.
|
||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -80,7 +80,7 @@ impl Engine {
|
|||||||
self.run_with_scope(scope, script)
|
self.run_with_scope(scope, script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an AST, but throw away the result and only return error (if any).
|
/// Evaluate an [`AST`], but throw away the result and only return error (if any).
|
||||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||||
///
|
///
|
||||||
/// # Deprecated
|
/// # Deprecated
|
||||||
|
@ -31,9 +31,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -17,11 +17,11 @@ impl Engine {
|
|||||||
/// > ` -> Result<Option<Dynamic>, Box<EvalAltResult>> + 'static`
|
/// > ` -> Result<Option<Dynamic>, Box<EvalAltResult>> + 'static`
|
||||||
///
|
///
|
||||||
/// where:
|
/// where:
|
||||||
/// * `index`: an offset from the bottom of the current [`Scope`] that the variable is supposed
|
/// * `index`: an offset from the bottom of the current [`Scope`][crate::Scope] that the
|
||||||
/// to reside. Offsets start from 1, with 1 meaning the last variable in the current
|
/// variable is supposed to reside. Offsets start from 1, with 1 meaning the last variable in
|
||||||
/// [`Scope`]. Essentially the correct variable is at position `scope.len() - index`.
|
/// the current [`Scope`][crate::Scope]. Essentially the correct variable is at position
|
||||||
/// If `index` is zero, then there is no pre-calculated offset position and a search through the
|
/// `scope.len() - index`. If `index` is zero, then there is no pre-calculated offset position
|
||||||
/// current [`Scope`] must be performed.
|
/// and a search through the current [`Scope`][crate::Scope] must be performed.
|
||||||
///
|
///
|
||||||
/// * `context`: the current [evaluation context][`EvalContext`].
|
/// * `context`: the current [evaluation context][`EvalContext`].
|
||||||
///
|
///
|
||||||
|
@ -71,9 +71,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -136,9 +136,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -180,9 +180,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
//! Module defining the public API of the Rhai engine.
|
//! Module defining the public API of the Rhai engine.
|
||||||
|
|
||||||
pub mod call_fn;
|
|
||||||
pub mod compile;
|
|
||||||
pub mod deprecated;
|
|
||||||
pub mod eval;
|
pub mod eval;
|
||||||
pub mod events;
|
|
||||||
|
pub mod run;
|
||||||
|
|
||||||
|
pub mod compile;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||||
pub mod files;
|
pub mod files;
|
||||||
|
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
|
pub mod call_fn;
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
pub mod limits;
|
pub mod limits;
|
||||||
pub mod register;
|
|
||||||
pub mod run;
|
pub mod events;
|
||||||
|
|
||||||
|
pub mod deprecated;
|
||||||
|
|
||||||
use crate::engine::Precedence;
|
use crate::engine::Precedence;
|
||||||
use crate::tokenizer::Token;
|
use crate::tokenizer::Token;
|
||||||
@ -43,21 +51,21 @@ impl Engine {
|
|||||||
pub const fn optimization_level(&self) -> crate::OptimizationLevel {
|
pub const fn optimization_level(&self) -> crate::OptimizationLevel {
|
||||||
self.optimization_level
|
self.optimization_level
|
||||||
}
|
}
|
||||||
/// Optimize the [`AST`] with constants defined in an external Scope.
|
/// Optimize the [`AST`][crate::AST] with constants defined in an external Scope. An optimized
|
||||||
/// An optimized copy of the [`AST`] is returned while the original [`AST`] is consumed.
|
/// copy of the [`AST`][crate::AST] is returned while the original [`AST`][crate::AST] is consumed.
|
||||||
///
|
///
|
||||||
/// Not available under `no_optimize`.
|
/// Not available under `no_optimize`.
|
||||||
///
|
///
|
||||||
/// Although optimization is performed by default during compilation, sometimes it is necessary to
|
/// Although optimization is performed by default during compilation, sometimes it is necessary
|
||||||
/// _re_-optimize an [`AST`]. For example, when working with constants that are passed in via an
|
/// to _re_-optimize an [`AST`][crate::AST]. For example, when working with constants that are
|
||||||
/// external scope, it will be more efficient to optimize the [`AST`] once again to take advantage
|
/// passed in via an external scope, it will be more efficient to optimize the
|
||||||
/// of the new constants.
|
/// [`AST`][crate::AST] once again to take advantage of the new constants.
|
||||||
///
|
///
|
||||||
/// With this method, it is no longer necessary to recompile a large script.
|
/// With this method, it is no longer necessary to recompile a large script. The script
|
||||||
/// The script [`AST`] can be compiled just once. Before evaluation,
|
/// [`AST`][crate::AST] can be compiled just once. Before evaluation, constants are passed into
|
||||||
/// constants are passed into the [`Engine`] via an external scope
|
/// the [`Engine`] via an external scope (i.e. with
|
||||||
/// (i.e. with [`Scope::push_constant`]).
|
/// [`Scope::push_constant`][crate::Scope::push_constant]). Then, the [`AST`][crate::AST] is
|
||||||
/// Then, the [`AST`] is cloned and the copy re-optimized before running.
|
/// cloned and the copy re-optimized before running.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn optimize_ast(
|
pub fn optimize_ast(
|
||||||
|
@ -154,7 +154,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// This function is very low level. It takes a list of [`TypeId`][std::any::TypeId]'s indicating the actual types of the parameters.
|
/// This function is very low level. It takes a list of [`TypeId`][std::any::TypeId]'s indicating the actual types of the parameters.
|
||||||
///
|
///
|
||||||
/// Arguments are simply passed in as a mutable array of [`&mut Dynamic`][Dynamic],
|
/// Arguments are simply passed in as a mutable array of [`&mut Dynamic`][crate::Dynamic],
|
||||||
/// The arguments are guaranteed to be of the correct types matching the [`TypeId`][std::any::TypeId]'s.
|
/// The arguments are guaranteed to be of the correct types matching the [`TypeId`][std::any::TypeId]'s.
|
||||||
///
|
///
|
||||||
/// To access a primary argument value (i.e. cloning is cheap), use: `args[n].as_xxx().unwrap()`
|
/// To access a primary argument value (i.e. cloning is cheap), use: `args[n].as_xxx().unwrap()`
|
||||||
|
@ -16,9 +16,9 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// ## Constants Propagation
|
/// ## Constants Propagation
|
||||||
///
|
///
|
||||||
/// If not [`OptimizationLevel::None`], constants defined within the scope are propagated
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// throughout the script _including_ functions. This allows functions to be optimized based on
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn run_with_scope(
|
pub fn run_with_scope(
|
||||||
&self,
|
&self,
|
||||||
@ -40,7 +40,7 @@ impl Engine {
|
|||||||
|
|
||||||
self.run_ast_with_scope(scope, &ast)
|
self.run_ast_with_scope(scope, &ast)
|
||||||
}
|
}
|
||||||
/// Evaluate an AST, returning any error (if any).
|
/// Evaluate an [`AST`], returning any error (if any).
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn run_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
pub fn run_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
||||||
self.run_ast_with_scope(&mut Scope::new(), ast)
|
self.run_ast_with_scope(&mut Scope::new(), ast)
|
||||||
|
@ -1011,7 +1011,7 @@ pub struct Engine {
|
|||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
pub(crate) progress: Option<crate::func::native::OnProgressCallback>,
|
pub(crate) progress: Option<crate::func::native::OnProgressCallback>,
|
||||||
|
|
||||||
/// Optimize the AST after compilation.
|
/// Optimize the [`AST`][crate::AST] after compilation.
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
pub(crate) optimization_level: crate::OptimizationLevel,
|
pub(crate) optimization_level: crate::OptimizationLevel,
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ use std::prelude::v1::*;
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use crate::FLOAT;
|
use crate::FLOAT;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[cfg(feature = "no_std")]
|
||||||
|
use num_traits::Float;
|
||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
@ -48,10 +52,6 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
x: &Dynamic,
|
x: &Dynamic,
|
||||||
y: &Dynamic,
|
y: &Dynamic,
|
||||||
) -> Option<fn(NativeCallContext, &mut FnCallArgs) -> RhaiResult> {
|
) -> Option<fn(NativeCallContext, &mut FnCallArgs) -> RhaiResult> {
|
||||||
#[cfg(feature = "no_std")]
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
|
||||||
use num_traits::Float;
|
|
||||||
|
|
||||||
let type1 = x.type_id();
|
let type1 = x.type_id();
|
||||||
let type2 = y.type_id();
|
let type2 = y.type_id();
|
||||||
|
|
||||||
@ -127,9 +127,9 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
} };
|
} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
#[cfg(not(feature = "no_float"))]
|
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+" => Some(impl_op!(FLOAT => $xx + $yy)),
|
"+" => Some(impl_op!(FLOAT => $xx + $yy)),
|
||||||
@ -150,13 +150,16 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_float!(FLOAT, as_float, FLOAT, as_float);
|
#[cfg(not(feature = "no_float"))]
|
||||||
impl_float!(FLOAT, as_float, INT, as_int);
|
{
|
||||||
impl_float!(INT, as_int, FLOAT, as_float);
|
impl_float!(FLOAT, as_float, FLOAT, as_float);
|
||||||
|
impl_float!(FLOAT, as_float, INT, as_int);
|
||||||
|
impl_float!(INT, as_int, FLOAT, as_float);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
macro_rules! impl_decimal {
|
macro_rules! impl_decimal {
|
||||||
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
#[cfg(feature = "decimal")]
|
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
use crate::packages::arithmetic::decimal_functions::*;
|
use crate::packages::arithmetic::decimal_functions::*;
|
||||||
@ -199,9 +202,12 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_decimal!(Decimal, as_decimal, Decimal, as_decimal);
|
#[cfg(feature = "decimal")]
|
||||||
impl_decimal!(Decimal, as_decimal, INT, as_int);
|
{
|
||||||
impl_decimal!(INT, as_int, Decimal, as_decimal);
|
impl_decimal!(Decimal, as_decimal, Decimal, as_decimal);
|
||||||
|
impl_decimal!(Decimal, as_decimal, INT, as_int);
|
||||||
|
impl_decimal!(INT, as_int, Decimal, as_decimal);
|
||||||
|
}
|
||||||
|
|
||||||
// char op string
|
// char op string
|
||||||
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
||||||
@ -419,10 +425,6 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
x: &Dynamic,
|
x: &Dynamic,
|
||||||
y: &Dynamic,
|
y: &Dynamic,
|
||||||
) -> Option<fn(NativeCallContext, &mut FnCallArgs) -> RhaiResult> {
|
) -> Option<fn(NativeCallContext, &mut FnCallArgs) -> RhaiResult> {
|
||||||
#[cfg(feature = "no_std")]
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
|
||||||
use num_traits::Float;
|
|
||||||
|
|
||||||
let type1 = x.type_id();
|
let type1 = x.type_id();
|
||||||
let type2 = y.type_id();
|
let type2 = y.type_id();
|
||||||
|
|
||||||
@ -468,9 +470,9 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
} };
|
} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
#[cfg(not(feature = "no_float"))]
|
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(impl_op!($x += $yy)),
|
"+=" => Some(impl_op!($x += $yy)),
|
||||||
@ -485,12 +487,15 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_float!(FLOAT, as_float, FLOAT, as_float);
|
#[cfg(not(feature = "no_float"))]
|
||||||
impl_float!(FLOAT, as_float, INT, as_int);
|
{
|
||||||
|
impl_float!(FLOAT, as_float, FLOAT, as_float);
|
||||||
|
impl_float!(FLOAT, as_float, INT, as_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
macro_rules! impl_decimal {
|
macro_rules! impl_decimal {
|
||||||
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
#[cfg(feature = "decimal")]
|
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
use crate::packages::arithmetic::decimal_functions::*;
|
use crate::packages::arithmetic::decimal_functions::*;
|
||||||
@ -523,8 +528,11 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_decimal!(Decimal, as_decimal, Decimal, as_decimal);
|
#[cfg(feature = "decimal")]
|
||||||
impl_decimal!(Decimal, as_decimal, INT, as_int);
|
{
|
||||||
|
impl_decimal!(Decimal, as_decimal, Decimal, as_decimal);
|
||||||
|
impl_decimal!(Decimal, as_decimal, INT, as_int);
|
||||||
|
}
|
||||||
|
|
||||||
// string op= char
|
// string op= char
|
||||||
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
||||||
|
@ -329,13 +329,10 @@ mod f32_functions {
|
|||||||
}
|
}
|
||||||
#[rhai_fn(return_raw)]
|
#[rhai_fn(return_raw)]
|
||||||
pub fn sign(x: f32) -> Result<INT, Box<EvalAltResult>> {
|
pub fn sign(x: f32) -> Result<INT, Box<EvalAltResult>> {
|
||||||
if x == 0.0 {
|
match x.signum() {
|
||||||
Ok(0)
|
_ if x == 0.0 => Ok(0),
|
||||||
} else {
|
x if x.is_nan() => Err(make_err("Sign of NaN is undefined")),
|
||||||
match x.signum() {
|
x => Ok(x as INT),
|
||||||
x if x.is_nan() => Err(make_err("Sign of NaN is undefined")),
|
|
||||||
x => Ok(x as INT),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_zero(x: f32) -> bool {
|
pub fn is_zero(x: f32) -> bool {
|
||||||
@ -439,13 +436,10 @@ mod f64_functions {
|
|||||||
}
|
}
|
||||||
#[rhai_fn(return_raw)]
|
#[rhai_fn(return_raw)]
|
||||||
pub fn sign(x: f64) -> Result<INT, Box<EvalAltResult>> {
|
pub fn sign(x: f64) -> Result<INT, Box<EvalAltResult>> {
|
||||||
if x == 0.0 {
|
match x.signum() {
|
||||||
Ok(0)
|
_ if x == 0.0 => Ok(0),
|
||||||
} else {
|
x if x.is_nan() => Err(make_err("Sign of NaN is undefined")),
|
||||||
match x.signum() {
|
x => Ok(x as INT),
|
||||||
x if x.is_nan() => Err(make_err("Sign of NaN is undefined")),
|
|
||||||
x => Ok(x as INT),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_zero(x: f64) -> bool {
|
pub fn is_zero(x: f64) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user