From 8c26b49a394514f6bd71d353f9ee7de0181cc754 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 10 Feb 2021 12:10:50 +0800 Subject: [PATCH] Change trig functions to take/return radians. --- RELEASES.md | 1 + src/packages/math_basic.rs | 24 ++++++++++++------------ tests/math.rs | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 473ad1d5..c1121f29 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -13,6 +13,7 @@ Bug fixes Breaking changes ---------------- +* Trigonometry functions now take radians and return radians instead of degrees. * `Dynamic::into_shared` is no longer available under `no_closure`. It used to panic. Enhancements diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index 06cd52ab..bc7f87c0 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -112,40 +112,40 @@ mod trig_functions { use crate::FLOAT; pub fn sin(x: FLOAT) -> FLOAT { - x.to_radians().sin() + x.sin() } pub fn cos(x: FLOAT) -> FLOAT { - x.to_radians().cos() + x.cos() } pub fn tan(x: FLOAT) -> FLOAT { - x.to_radians().tan() + x.tan() } pub fn sinh(x: FLOAT) -> FLOAT { - x.to_radians().sinh() + x.sinh() } pub fn cosh(x: FLOAT) -> FLOAT { - x.to_radians().cosh() + x.cosh() } pub fn tanh(x: FLOAT) -> FLOAT { - x.to_radians().tanh() + x.tanh() } pub fn asin(x: FLOAT) -> FLOAT { - x.asin().to_degrees() + x.asin() } pub fn acos(x: FLOAT) -> FLOAT { - x.acos().to_degrees() + x.acos() } pub fn atan(x: FLOAT) -> FLOAT { - x.atan().to_degrees() + x.atan() } pub fn asinh(x: FLOAT) -> FLOAT { - x.asinh().to_degrees() + x.asinh() } pub fn acosh(x: FLOAT) -> FLOAT { - x.acosh().to_degrees() + x.acosh() } pub fn atanh(x: FLOAT) -> FLOAT { - x.atanh().to_degrees() + x.atanh() } } diff --git a/tests/math.rs b/tests/math.rs index fa398c83..25bf1228 100644 --- a/tests/math.rs +++ b/tests/math.rs @@ -14,10 +14,10 @@ fn test_math() -> Result<(), Box> { assert_eq!(engine.eval::("3 % 2")?, 1); #[cfg(not(feature = "no_float"))] - assert!((engine.eval::("sin(30.0)")? - 0.5).abs() < 0.001); + assert!((engine.eval::("sin(PI()/6.0)")? - 0.5).abs() < 0.001); #[cfg(not(feature = "no_float"))] - assert!(engine.eval::("cos(90.0)")?.abs() < 0.001); + assert!(engine.eval::("cos(PI()/2.0)")?.abs() < 0.001); #[cfg(not(feature = "only_i32"))] assert_eq!(