]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/cmath.rs
64fc14d42d9b77f0884c5a4749bb336ca0c237e1
[rust.git] / src / libstd / sys / wasm / cmath.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #[inline]
12 pub unsafe fn cbrtf(n: f32) -> f32 {
13     f64::cbrt(n as f64) as f32
14 }
15
16 #[inline]
17 pub unsafe fn expm1f(n: f32) -> f32 {
18     f64::exp_m1(n as f64) as f32
19 }
20
21 #[inline]
22 #[allow(deprecated)]
23 pub unsafe fn fdimf(a: f32, b: f32) -> f32 {
24     f64::abs_sub(a as f64, b as f64) as f32
25 }
26
27 #[inline]
28 pub unsafe fn log1pf(n: f32) -> f32 {
29     f64::ln_1p(n as f64) as f32
30 }
31
32 #[inline]
33 pub unsafe fn hypotf(x: f32, y: f32) -> f32 {
34     f64::hypot(x as f64, y as f64) as f32
35 }
36
37 #[inline]
38 pub unsafe fn acosf(n: f32) -> f32 {
39     f64::acos(n as f64) as f32
40 }
41
42 #[inline]
43 pub unsafe fn asinf(n: f32) -> f32 {
44     f64::asin(n as f64) as f32
45 }
46
47 #[inline]
48 pub unsafe fn atan2f(n: f32, b: f32) -> f32 {
49     f64::atan2(n as f64, b as f64) as f32
50 }
51
52 #[inline]
53 pub unsafe fn atanf(n: f32) -> f32 {
54     f64::atan(n as f64) as f32
55 }
56
57 #[inline]
58 pub unsafe fn coshf(n: f32) -> f32 {
59     f64::cosh(n as f64) as f32
60 }
61
62 #[inline]
63 pub unsafe fn sinhf(n: f32) -> f32 {
64     f64::sinh(n as f64) as f32
65 }
66
67 #[inline]
68 pub unsafe fn tanf(n: f32) -> f32 {
69     f64::tan(n as f64) as f32
70 }
71
72 #[inline]
73 pub unsafe fn tanhf(n: f32) -> f32 {
74     f64::tanh(n as f64) as f32
75 }
76
77 // These symbols are all defined in `compiler-builtins`
78 extern {
79     pub fn acos(n: f64) -> f64;
80     pub fn asin(n: f64) -> f64;
81     pub fn atan(n: f64) -> f64;
82     pub fn atan2(a: f64, b: f64) -> f64;
83     pub fn cbrt(n: f64) -> f64;
84     pub fn cosh(n: f64) -> f64;
85     pub fn expm1(n: f64) -> f64;
86     pub fn fdim(a: f64, b: f64) -> f64;
87     pub fn log1p(n: f64) -> f64;
88     pub fn sinh(n: f64) -> f64;
89     pub fn tan(n: f64) -> f64;
90     pub fn tanh(n: f64) -> f64;
91     pub fn hypot(x: f64, y: f64) -> f64;
92 }