Move some math functions into plugins.

This commit is contained in:
Stephen Chung
2020-08-13 14:57:46 +08:00
parent 631c4be064
commit b956639c2a
2 changed files with 131 additions and 51 deletions

View File

@@ -1,5 +1,8 @@
use rhai::{Engine, EvalAltResult, INT};
#[cfg(not(feature = "no_float"))]
use rhai::FLOAT;
#[test]
fn test_math() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
@@ -10,6 +13,12 @@ fn test_math() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>("1 / 2")?, 0);
assert_eq!(engine.eval::<INT>("3 % 2")?, 1);
#[cfg(not(feature = "no_float"))]
assert!((engine.eval::<FLOAT>("sin(30.0)")? - 0.5).abs() < 0.001);
#[cfg(not(feature = "no_float"))]
assert!(engine.eval::<FLOAT>("cos(90.0)")?.abs() < 0.001);
#[cfg(not(feature = "only_i32"))]
assert_eq!(
engine.eval::<INT>("abs(-9223372036854775807)")?,