Fixed semantic errors

This commit is contained in:
PaddiM8 2021-01-03 00:19:22 +01:00
parent 9591241b8d
commit ae5fdf215e
2 changed files with 13 additions and 19 deletions

View File

@ -69,15 +69,9 @@ impl KalkNum {
format!("{} {}", self.to_string(), self.unit) format!("{} {}", self.to_string(), self.unit)
} }
#[cfg(not(target_arch = "wasm32"))]
pub fn get_unit(&self) -> &str {
&self.unit
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(js_name = getUnit)] #[wasm_bindgen(js_name = getUnit)]
pub fn get_unit(&self) -> String { pub fn get_unit(&self) -> String {
self.unit.clone().into() self.unit.clone()
} }
#[wasm_bindgen(js_name = hasUnit)] #[wasm_bindgen(js_name = hasUnit)]

View File

@ -96,7 +96,7 @@ fn from_angle_unit(context: &mut interpreter::Context, x: f64, angle_unit: &str)
pub mod special_funcs { pub mod special_funcs {
pub fn factorial(x: f64) -> f64 { pub fn factorial(x: f64) -> f64 {
funcs::gamma(x) - 1 super::funcs::gamma(x) - 1f64
} }
} }
@ -200,24 +200,24 @@ pub(super) mod funcs {
// Matthias Eiholzer - https://gitlab.com/matthiaseiholzer/mathru/-/tree/master // Matthias Eiholzer - https://gitlab.com/matthiaseiholzer/mathru/-/tree/master
pub fn gamma(x: f64) -> f64 { pub fn gamma(x: f64) -> f64 {
let pi = 3.1415926535897932384626433832795028841971693993751058209749445923f64; let pi = 3.1415926535897932384626433832795028841971693993751058209749445923f64;
if x == 0.0 { if x == 0f64 {
return f64::NAN; return f64::NAN;
} }
if x < 0.5 { if x < 0.5f64 {
return pi / ((pi * x).sin() * (1.0 - x).gamma()); return pi / gamma((pi * x).sin() * (1f64 - x));
} }
let t = x + 6.5; let t = x + 6.5;
let x = 0.99999999999980993 + 676.5203681218851 / x - 1259.1392167224028 / (x + 1.0) let x = 0.99999999999980993 + 676.5203681218851 / x - 1259.1392167224028 / (x + 1f64)
+ 771.32342877765313 / (x + 2.0) + 771.32342877765313 / (x + 2f64)
- 176.61502916214059 / (x + 3.0) - 176.61502916214059 / (x + 3f64)
+ 12.507343278686905 / (x + 4.0) + 12.507343278686905 / (x + 4f64)
- 0.13857109526572012 / (x + 5.0) - 0.13857109526572012 / (x + 5f64)
+ 9.9843695780195716e-6 / (x + 6.0) + 9.9843695780195716e-6 / (x + 6f64)
+ 1.5056327351493116e-7 / (x + 7.0); + 1.5056327351493116e-7 / (x + 7f64);
2.0.sqrt() * pi.sqrt() * t.pow((x - 0.5)) * (-t).exp() * x 2f64.sqrt() * pi.sqrt() * t.powf(x - 0.5f64) * (-t).exp() * x
} }
pub fn hyp(x: f64, y: f64) -> f64 { pub fn hyp(x: f64, y: f64) -> f64 {