Change trig functions to take/return radians.
This commit is contained in:
parent
8f47f7c9e2
commit
8c26b49a39
@ -13,6 +13,7 @@ Bug fixes
|
|||||||
Breaking changes
|
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.
|
* `Dynamic::into_shared` is no longer available under `no_closure`. It used to panic.
|
||||||
|
|
||||||
Enhancements
|
Enhancements
|
||||||
|
@ -112,40 +112,40 @@ mod trig_functions {
|
|||||||
use crate::FLOAT;
|
use crate::FLOAT;
|
||||||
|
|
||||||
pub fn sin(x: FLOAT) -> FLOAT {
|
pub fn sin(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().sin()
|
x.sin()
|
||||||
}
|
}
|
||||||
pub fn cos(x: FLOAT) -> FLOAT {
|
pub fn cos(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().cos()
|
x.cos()
|
||||||
}
|
}
|
||||||
pub fn tan(x: FLOAT) -> FLOAT {
|
pub fn tan(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().tan()
|
x.tan()
|
||||||
}
|
}
|
||||||
pub fn sinh(x: FLOAT) -> FLOAT {
|
pub fn sinh(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().sinh()
|
x.sinh()
|
||||||
}
|
}
|
||||||
pub fn cosh(x: FLOAT) -> FLOAT {
|
pub fn cosh(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().cosh()
|
x.cosh()
|
||||||
}
|
}
|
||||||
pub fn tanh(x: FLOAT) -> FLOAT {
|
pub fn tanh(x: FLOAT) -> FLOAT {
|
||||||
x.to_radians().tanh()
|
x.tanh()
|
||||||
}
|
}
|
||||||
pub fn asin(x: FLOAT) -> FLOAT {
|
pub fn asin(x: FLOAT) -> FLOAT {
|
||||||
x.asin().to_degrees()
|
x.asin()
|
||||||
}
|
}
|
||||||
pub fn acos(x: FLOAT) -> FLOAT {
|
pub fn acos(x: FLOAT) -> FLOAT {
|
||||||
x.acos().to_degrees()
|
x.acos()
|
||||||
}
|
}
|
||||||
pub fn atan(x: FLOAT) -> FLOAT {
|
pub fn atan(x: FLOAT) -> FLOAT {
|
||||||
x.atan().to_degrees()
|
x.atan()
|
||||||
}
|
}
|
||||||
pub fn asinh(x: FLOAT) -> FLOAT {
|
pub fn asinh(x: FLOAT) -> FLOAT {
|
||||||
x.asinh().to_degrees()
|
x.asinh()
|
||||||
}
|
}
|
||||||
pub fn acosh(x: FLOAT) -> FLOAT {
|
pub fn acosh(x: FLOAT) -> FLOAT {
|
||||||
x.acosh().to_degrees()
|
x.acosh()
|
||||||
}
|
}
|
||||||
pub fn atanh(x: FLOAT) -> FLOAT {
|
pub fn atanh(x: FLOAT) -> FLOAT {
|
||||||
x.atanh().to_degrees()
|
x.atanh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ fn test_math() -> Result<(), Box<EvalAltResult>> {
|
|||||||
assert_eq!(engine.eval::<INT>("3 % 2")?, 1);
|
assert_eq!(engine.eval::<INT>("3 % 2")?, 1);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
assert!((engine.eval::<FLOAT>("sin(30.0)")? - 0.5).abs() < 0.001);
|
assert!((engine.eval::<FLOAT>("sin(PI()/6.0)")? - 0.5).abs() < 0.001);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
assert!(engine.eval::<FLOAT>("cos(90.0)")?.abs() < 0.001);
|
assert!(engine.eval::<FLOAT>("cos(PI()/2.0)")?.abs() < 0.001);
|
||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
Loading…
Reference in New Issue
Block a user