14
14
15
15
use prelude:: * ;
16
16
17
- use cmath;
18
17
use default:: Default ;
19
18
use from_str:: FromStr ;
20
19
use libc:: { c_float, c_int} ;
@@ -23,6 +22,46 @@ use num::{Zero, One, Bounded, strconv};
23
22
use num;
24
23
use intrinsics;
25
24
25
+ #[ allow( dead_code) ]
26
+ mod cmath {
27
+ use libc:: { c_float, c_int} ;
28
+
29
+ #[ link_name = "m" ]
30
+ extern {
31
+ pub fn acosf ( n : c_float ) -> c_float ;
32
+ pub fn asinf ( n : c_float ) -> c_float ;
33
+ pub fn atanf ( n : c_float ) -> c_float ;
34
+ pub fn atan2f ( a : c_float , b : c_float ) -> c_float ;
35
+ pub fn cbrtf ( n : c_float ) -> c_float ;
36
+ pub fn coshf ( n : c_float ) -> c_float ;
37
+ pub fn erff ( n : c_float ) -> c_float ;
38
+ pub fn erfcf ( n : c_float ) -> c_float ;
39
+ pub fn expm1f ( n : c_float ) -> c_float ;
40
+ pub fn fdimf ( a : c_float , b : c_float ) -> c_float ;
41
+ pub fn frexpf ( n : c_float , value : & mut c_int ) -> c_float ;
42
+ pub fn fmaxf ( a : c_float , b : c_float ) -> c_float ;
43
+ pub fn fminf ( a : c_float , b : c_float ) -> c_float ;
44
+ pub fn nextafterf ( x : c_float , y : c_float ) -> c_float ;
45
+ pub fn hypotf ( x : c_float , y : c_float ) -> c_float ;
46
+ pub fn ldexpf ( x : c_float , n : c_int ) -> c_float ;
47
+ pub fn logbf ( n : c_float ) -> c_float ;
48
+ pub fn log1pf ( n : c_float ) -> c_float ;
49
+ pub fn ilogbf ( n : c_float ) -> c_int ;
50
+ pub fn modff ( n : c_float , iptr : & mut c_float ) -> c_float ;
51
+ pub fn sinhf ( n : c_float ) -> c_float ;
52
+ pub fn tanf ( n : c_float ) -> c_float ;
53
+ pub fn tanhf ( n : c_float ) -> c_float ;
54
+ pub fn tgammaf ( n : c_float ) -> c_float ;
55
+
56
+ #[ cfg( unix) ]
57
+ pub fn lgammaf_r ( n : c_float , sign : & mut c_int ) -> c_float ;
58
+
59
+ #[ cfg( windows) ]
60
+ #[ link_name="__lgammaf_r" ]
61
+ pub fn lgammaf_r ( n : c_float , sign : & mut c_int ) -> c_float ;
62
+ }
63
+ }
64
+
26
65
macro_rules! delegate(
27
66
(
28
67
$(
@@ -66,29 +105,22 @@ delegate!(
66
105
fn nearbyint( n: f32 ) -> f32 = intrinsics:: nearbyintf32,
67
106
fn round( n: f32 ) -> f32 = intrinsics:: roundf32,
68
107
69
- // cmath
70
- fn acos( n: c_float) -> c_float = cmath:: c_float:: acos,
71
- fn asin( n: c_float) -> c_float = cmath:: c_float:: asin,
72
- fn atan( n: c_float) -> c_float = cmath:: c_float:: atan,
73
- fn atan2( a: c_float, b: c_float) -> c_float = cmath:: c_float:: atan2,
74
- fn cbrt( n: c_float) -> c_float = cmath:: c_float:: cbrt,
75
- fn cosh( n: c_float) -> c_float = cmath:: c_float:: cosh,
76
- // fn erf(n: c_float) -> c_float = cmath::c_float::erf,
77
- // fn erfc(n: c_float) -> c_float = cmath::c_float::erfc,
78
- fn exp_m1( n: c_float) -> c_float = cmath:: c_float:: exp_m1,
79
- fn abs_sub( a: c_float, b: c_float) -> c_float = cmath:: c_float:: abs_sub,
80
- fn next_after( x: c_float, y: c_float) -> c_float = cmath:: c_float:: next_after,
81
- fn frexp( n: c_float, value: & mut c_int) -> c_float = cmath:: c_float:: frexp,
82
- fn hypot( x: c_float, y: c_float) -> c_float = cmath:: c_float:: hypot,
83
- fn ldexp( x: c_float, n: c_int) -> c_float = cmath:: c_float:: ldexp,
84
- // fn log_radix(n: c_float) -> c_float = cmath::c_float::log_radix,
85
- fn ln_1p( n: c_float) -> c_float = cmath:: c_float:: ln_1p,
86
- // fn ilog_radix(n: c_float) -> c_int = cmath::c_float::ilog_radix,
87
- // fn modf(n: c_float, iptr: &mut c_float) -> c_float = cmath::c_float::modf,
88
- // fn ldexp_radix(n: c_float, i: c_int) -> c_float = cmath::c_float::ldexp_radix,
89
- fn sinh( n: c_float) -> c_float = cmath:: c_float:: sinh,
90
- fn tan( n: c_float) -> c_float = cmath:: c_float:: tan,
91
- fn tanh( n: c_float) -> c_float = cmath:: c_float:: tanh
108
+ fn acos( n: c_float) -> c_float = cmath:: acosf,
109
+ fn asin( n: c_float) -> c_float = cmath:: asinf,
110
+ fn atan( n: c_float) -> c_float = cmath:: atanf,
111
+ fn atan2( a: c_float, b: c_float) -> c_float = cmath:: atan2f,
112
+ fn cbrt( n: c_float) -> c_float = cmath:: cbrtf,
113
+ fn cosh( n: c_float) -> c_float = cmath:: coshf,
114
+ fn exp_m1( n: c_float) -> c_float = cmath:: expm1f,
115
+ fn abs_sub( a: c_float, b: c_float) -> c_float = cmath:: fdimf,
116
+ fn next_after( x: c_float, y: c_float) -> c_float = cmath:: nextafterf,
117
+ fn frexp( n: c_float, value: & mut c_int) -> c_float = cmath:: frexpf,
118
+ fn hypot( x: c_float, y: c_float) -> c_float = cmath:: hypotf,
119
+ fn ldexp( x: c_float, n: c_int) -> c_float = cmath:: ldexpf,
120
+ fn ln_1p( n: c_float) -> c_float = cmath:: log1pf,
121
+ fn sinh( n: c_float) -> c_float = cmath:: sinhf,
122
+ fn tan( n: c_float) -> c_float = cmath:: tanf,
123
+ fn tanh( n: c_float) -> c_float = cmath:: tanhf
92
124
)
93
125
94
126
// FIXME(#11621): These constants should be deprecated once CTFE is implemented
@@ -308,12 +340,12 @@ impl Primitive for f32 {}
308
340
impl Float for f32 {
309
341
#[ inline]
310
342
fn max ( self , other : f32 ) -> f32 {
311
- unsafe { cmath:: c_float :: fmax ( self , other) }
343
+ unsafe { cmath:: fmaxf ( self , other) }
312
344
}
313
345
314
346
#[ inline]
315
347
fn min ( self , other : f32 ) -> f32 {
316
- unsafe { cmath:: c_float :: fmin ( self , other) }
348
+ unsafe { cmath:: fminf ( self , other) }
317
349
}
318
350
319
351
#[ inline]
0 commit comments