1 | #![cfg (not(test))] |
2 | |
3 | // These symbols are all defined by `libm`, |
4 | // or by `compiler-builtins` on unsupported platforms. |
5 | extern "C" { |
6 | pub fn acos(n: f64) -> f64; |
7 | pub fn asin(n: f64) -> f64; |
8 | pub fn atan(n: f64) -> f64; |
9 | pub fn atan2(a: f64, b: f64) -> f64; |
10 | pub fn cbrt(n: f64) -> f64; |
11 | pub fn cbrtf(n: f32) -> f32; |
12 | pub fn cosh(n: f64) -> f64; |
13 | pub fn expm1(n: f64) -> f64; |
14 | pub fn expm1f(n: f32) -> f32; |
15 | pub fn fdim(a: f64, b: f64) -> f64; |
16 | pub fn fdimf(a: f32, b: f32) -> f32; |
17 | #[cfg_attr (target_env = "msvc" , link_name = "_hypot" )] |
18 | pub fn hypot(x: f64, y: f64) -> f64; |
19 | #[cfg_attr (target_env = "msvc" , link_name = "_hypotf" )] |
20 | pub fn hypotf(x: f32, y: f32) -> f32; |
21 | pub fn log1p(n: f64) -> f64; |
22 | pub fn log1pf(n: f32) -> f32; |
23 | pub fn sinh(n: f64) -> f64; |
24 | pub fn tan(n: f64) -> f64; |
25 | pub fn tanh(n: f64) -> f64; |
26 | pub fn tgamma(n: f64) -> f64; |
27 | pub fn tgammaf(n: f32) -> f32; |
28 | pub fn lgamma_r(n: f64, s: &mut i32) -> f64; |
29 | pub fn lgammaf_r(n: f32, s: &mut i32) -> f32; |
30 | |
31 | cfg_if::cfg_if! { |
32 | if #[cfg(not(all(target_os = "windows" , target_env = "msvc" , target_arch = "x86" )))] { |
33 | pub fn acosf(n: f32) -> f32; |
34 | pub fn asinf(n: f32) -> f32; |
35 | pub fn atan2f(a: f32, b: f32) -> f32; |
36 | pub fn atanf(n: f32) -> f32; |
37 | pub fn coshf(n: f32) -> f32; |
38 | pub fn sinhf(n: f32) -> f32; |
39 | pub fn tanf(n: f32) -> f32; |
40 | pub fn tanhf(n: f32) -> f32; |
41 | }} |
42 | } |
43 | |
44 | // On 32-bit x86 MSVC these functions aren't defined, so we just define shims |
45 | // which promote everything to f64, perform the calculation, and then demote |
46 | // back to f32. While not precisely correct should be "correct enough" for now. |
47 | cfg_if::cfg_if! { |
48 | if #[cfg(all(target_os = "windows" , target_env = "msvc" , target_arch = "x86" ))] { |
49 | #[inline ] |
50 | pub unsafe fn acosf(n: f32) -> f32 { |
51 | f64::acos(n as f64) as f32 |
52 | } |
53 | |
54 | #[inline ] |
55 | pub unsafe fn asinf(n: f32) -> f32 { |
56 | f64::asin(n as f64) as f32 |
57 | } |
58 | |
59 | #[inline ] |
60 | pub unsafe fn atan2f(n: f32, b: f32) -> f32 { |
61 | f64::atan2(n as f64, b as f64) as f32 |
62 | } |
63 | |
64 | #[inline ] |
65 | pub unsafe fn atanf(n: f32) -> f32 { |
66 | f64::atan(n as f64) as f32 |
67 | } |
68 | |
69 | #[inline ] |
70 | pub unsafe fn coshf(n: f32) -> f32 { |
71 | f64::cosh(n as f64) as f32 |
72 | } |
73 | |
74 | #[inline ] |
75 | pub unsafe fn sinhf(n: f32) -> f32 { |
76 | f64::sinh(n as f64) as f32 |
77 | } |
78 | |
79 | #[inline ] |
80 | pub unsafe fn tanf(n: f32) -> f32 { |
81 | f64::tan(n as f64) as f32 |
82 | } |
83 | |
84 | #[inline ] |
85 | pub unsafe fn tanhf(n: f32) -> f32 { |
86 | f64::tanh(n as f64) as f32 |
87 | } |
88 | }} |
89 | |