]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/cmath.rs
Rollup merge of #54233 - irinagpopa:llvm-3.9, r=tromey
[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 // Right now all these functions, the f64 version of the functions above, all
78 // shell out to random names. These names aren't actually defined anywhere, per
79 // se, but we need this to compile somehow.
80 //
81 // The idea with this is that when you're using wasm then, for now, we have no
82 // way of providing an implementation of these which delegates to a "correct"
83 // implementation. For example most wasm applications probably just want to
84 // delegate to the javascript `Math` object and its related functions, but wasm
85 // doesn't currently have the ability to seamlessly do that (when you
86 // instantiate a module you have to set that up).
87 //
88 // As a result these are just defined here with "hopefully helpful" names. The
89 // symbols won't ever be needed or show up unless these functions are called,
90 // and hopefully when they're called the errors are self-explanatory enough to
91 // figure out what's going on.
92
93 extern {
94     #[link_name = "Math_acos"]
95     pub fn acos(n: f64) -> f64;
96     #[link_name = "Math_asin"]
97     pub fn asin(n: f64) -> f64;
98     #[link_name = "Math_atan"]
99     pub fn atan(n: f64) -> f64;
100     #[link_name = "Math_atan2"]
101     pub fn atan2(a: f64, b: f64) -> f64;
102     #[link_name = "Math_cbrt"]
103     pub fn cbrt(n: f64) -> f64;
104     #[link_name = "Math_cosh"]
105     pub fn cosh(n: f64) -> f64;
106     #[link_name = "Math_expm1"]
107     pub fn expm1(n: f64) -> f64;
108     pub fn fdim(a: f64, b: f64) -> f64;
109     #[link_name = "Math_log1p"]
110     pub fn log1p(n: f64) -> f64;
111     #[link_name = "Math_sinh"]
112     pub fn sinh(n: f64) -> f64;
113     #[link_name = "Math_tan"]
114     pub fn tan(n: f64) -> f64;
115     #[link_name = "Math_tanh"]
116     pub fn tanh(n: f64) -> f64;
117     #[link_name = "Math_hypot"]
118     pub fn hypot(x: f64, y: f64) -> f64;
119 }