10
10
11
11
//! Operations and constants for `f32`
12
12
13
- use cmath;
14
- use libc:: { c_float, c_int} ;
15
13
use num:: strconv;
16
14
use num;
17
15
use option:: Option ;
18
- use unstable:: intrinsics:: floorf32;
19
16
use from_str;
20
17
use to_str;
21
18
@@ -24,79 +21,93 @@ use to_str;
24
21
25
22
pub use cmath:: c_float_targ_consts:: * ;
26
23
24
+ // An inner module is required to get the #[inline(always)] attribute on the
25
+ // functions.
26
+ pub use self :: delegated:: * ;
27
+
27
28
macro_rules! delegate(
28
29
(
29
- fn $name: ident(
30
- $(
31
- $arg: ident : $arg_ty: ty
32
- ) ,*
33
- ) -> $rv: ty = $bound_name: path
30
+ $(
31
+ fn $name: ident(
32
+ $(
33
+ $arg: ident : $arg_ty: ty
34
+ ) ,*
35
+ ) -> $rv: ty = $bound_name: path
36
+ ) ,*
34
37
) => (
35
- pub fn $name( $( $arg : $arg_ty ) ,* ) -> $rv {
36
- unsafe {
37
- $bound_name( $( $arg ) ,* )
38
- }
38
+ mod delegated {
39
+ use cmath:: c_float_utils;
40
+ use libc:: { c_float, c_int} ;
41
+ use unstable:: intrinsics;
42
+
43
+ $(
44
+ #[ inline( always) ]
45
+ pub fn $name( $( $arg : $arg_ty ) ,* ) -> $rv {
46
+ unsafe {
47
+ $bound_name( $( $arg ) ,* )
48
+ }
49
+ }
50
+ ) *
39
51
}
40
52
)
41
53
)
42
54
43
- delegate ! ( fn acos( n: c_float) -> c_float = cmath:: c_float_utils:: acos)
44
- delegate ! ( fn asin( n: c_float) -> c_float = cmath:: c_float_utils:: asin)
45
- delegate ! ( fn atan( n: c_float) -> c_float = cmath:: c_float_utils:: atan)
46
- delegate ! ( fn atan2( a: c_float, b: c_float) -> c_float =
47
- cmath:: c_float_utils:: atan2)
48
- delegate ! ( fn cbrt( n: c_float) -> c_float = cmath:: c_float_utils:: cbrt)
49
- delegate ! ( fn ceil( n: c_float) -> c_float = cmath:: c_float_utils:: ceil)
50
- delegate ! ( fn copysign( x: c_float, y: c_float) -> c_float =
51
- cmath:: c_float_utils:: copysign)
52
- delegate ! ( fn cos( n: c_float) -> c_float = cmath:: c_float_utils:: cos)
53
- delegate ! ( fn cosh( n: c_float) -> c_float = cmath:: c_float_utils:: cosh)
54
- delegate ! ( fn erf( n: c_float) -> c_float = cmath:: c_float_utils:: erf)
55
- delegate ! ( fn erfc( n: c_float) -> c_float = cmath:: c_float_utils:: erfc)
56
- delegate ! ( fn exp( n: c_float) -> c_float = cmath:: c_float_utils:: exp)
57
- delegate ! ( fn expm1( n: c_float) -> c_float = cmath:: c_float_utils:: expm1)
58
- delegate ! ( fn exp2( n: c_float) -> c_float = cmath:: c_float_utils:: exp2)
59
- delegate ! ( fn abs( n: c_float) -> c_float = cmath:: c_float_utils:: abs)
60
- delegate ! ( fn abs_sub( a: c_float, b: c_float) -> c_float =
61
- cmath:: c_float_utils:: abs_sub)
62
- delegate ! ( fn mul_add( a: c_float, b: c_float, c: c_float) -> c_float =
63
- cmath:: c_float_utils:: mul_add)
64
- delegate ! ( fn fmax( a: c_float, b: c_float) -> c_float =
65
- cmath:: c_float_utils:: fmax)
66
- delegate ! ( fn fmin( a: c_float, b: c_float) -> c_float =
67
- cmath:: c_float_utils:: fmin)
68
- delegate ! ( fn nextafter( x: c_float, y: c_float) -> c_float =
69
- cmath:: c_float_utils:: nextafter)
70
- delegate ! ( fn frexp( n: c_float, value: & mut c_int) -> c_float =
71
- cmath:: c_float_utils:: frexp)
72
- delegate ! ( fn hypot( x: c_float, y: c_float) -> c_float =
73
- cmath:: c_float_utils:: hypot)
74
- delegate ! ( fn ldexp( x: c_float, n: c_int) -> c_float =
75
- cmath:: c_float_utils:: ldexp)
76
- delegate ! ( fn lgamma( n: c_float, sign: & mut c_int) -> c_float =
77
- cmath:: c_float_utils:: lgamma)
78
- delegate ! ( fn ln( n: c_float) -> c_float = cmath:: c_float_utils:: ln)
79
- delegate ! ( fn log_radix( n: c_float) -> c_float =
80
- cmath:: c_float_utils:: log_radix)
81
- delegate ! ( fn ln1p( n: c_float) -> c_float = cmath:: c_float_utils:: ln1p)
82
- delegate ! ( fn log10( n: c_float) -> c_float = cmath:: c_float_utils:: log10)
83
- delegate ! ( fn log2( n: c_float) -> c_float = cmath:: c_float_utils:: log2)
84
- delegate ! ( fn ilog_radix( n: c_float) -> c_int =
85
- cmath:: c_float_utils:: ilog_radix)
86
- delegate ! ( fn modf( n: c_float, iptr: & mut c_float) -> c_float =
87
- cmath:: c_float_utils:: modf)
88
- delegate ! ( fn pow( n: c_float, e: c_float) -> c_float =
89
- cmath:: c_float_utils:: pow)
90
- delegate ! ( fn round( n: c_float) -> c_float = cmath:: c_float_utils:: round)
91
- delegate ! ( fn ldexp_radix( n: c_float, i: c_int) -> c_float =
92
- cmath:: c_float_utils:: ldexp_radix)
93
- delegate ! ( fn sin( n: c_float) -> c_float = cmath:: c_float_utils:: sin)
94
- delegate ! ( fn sinh( n: c_float) -> c_float = cmath:: c_float_utils:: sinh)
95
- delegate ! ( fn sqrt( n: c_float) -> c_float = cmath:: c_float_utils:: sqrt)
96
- delegate ! ( fn tan( n: c_float) -> c_float = cmath:: c_float_utils:: tan)
97
- delegate ! ( fn tanh( n: c_float) -> c_float = cmath:: c_float_utils:: tanh)
98
- delegate ! ( fn tgamma( n: c_float) -> c_float = cmath:: c_float_utils:: tgamma)
99
- delegate ! ( fn trunc( n: c_float) -> c_float = cmath:: c_float_utils:: trunc)
55
+ delegate ! (
56
+ // intrinsics
57
+ fn abs( n: f32 ) -> f32 = intrinsics:: fabsf32,
58
+ fn cos( n: f32 ) -> f32 = intrinsics:: cosf32,
59
+ fn exp( n: f32 ) -> f32 = intrinsics:: expf32,
60
+ fn exp2( n: f32 ) -> f32 = intrinsics:: exp2f32,
61
+ fn floor( x: f32 ) -> f32 = intrinsics:: floorf32,
62
+ fn ln( n: f32 ) -> f32 = intrinsics:: logf32,
63
+ fn log10( n: f32 ) -> f32 = intrinsics:: log10f32,
64
+ fn log2( n: f32 ) -> f32 = intrinsics:: log2f32,
65
+ fn mul_add( a: f32 , b: f32 , c: f32 ) -> f32 = intrinsics:: fmaf32,
66
+ fn pow( n: f32 , e: f32 ) -> f32 = intrinsics:: powf32,
67
+ fn powi( n: f32 , e: c_int) -> f32 = intrinsics:: powif32,
68
+ fn sin( n: f32 ) -> f32 = intrinsics:: sinf32,
69
+ fn sqrt( n: f32 ) -> f32 = intrinsics:: sqrtf32,
70
+
71
+ // LLVM 3.3 required to use intrinsics for these four
72
+ fn ceil( n: c_float) -> c_float = c_float_utils:: ceil,
73
+ fn trunc( n: c_float) -> c_float = c_float_utils:: trunc,
74
+ /*
75
+ fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
76
+ fn trunc(n: f32) -> f32 = intrinsics::truncf32,
77
+ fn rint(n: f32) -> f32 = intrinsics::rintf32,
78
+ fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
79
+ */
80
+
81
+ // cmath
82
+ fn acos( n: c_float) -> c_float = c_float_utils:: acos,
83
+ fn asin( n: c_float) -> c_float = c_float_utils:: asin,
84
+ fn atan( n: c_float) -> c_float = c_float_utils:: atan,
85
+ fn atan2( a: c_float, b: c_float) -> c_float = c_float_utils:: atan2,
86
+ fn cbrt( n: c_float) -> c_float = c_float_utils:: cbrt,
87
+ fn copysign( x: c_float, y: c_float) -> c_float = c_float_utils:: copysign,
88
+ fn cosh( n: c_float) -> c_float = c_float_utils:: cosh,
89
+ fn erf( n: c_float) -> c_float = c_float_utils:: erf,
90
+ fn erfc( n: c_float) -> c_float = c_float_utils:: erfc,
91
+ fn expm1( n: c_float) -> c_float = c_float_utils:: expm1,
92
+ fn abs_sub( a: c_float, b: c_float) -> c_float = c_float_utils:: abs_sub,
93
+ fn fmax( a: c_float, b: c_float) -> c_float = c_float_utils:: fmax,
94
+ fn fmin( a: c_float, b: c_float) -> c_float = c_float_utils:: fmin,
95
+ fn nextafter( x: c_float, y: c_float) -> c_float = c_float_utils:: nextafter,
96
+ fn frexp( n: c_float, value: & mut c_int) -> c_float = c_float_utils:: frexp,
97
+ fn hypot( x: c_float, y: c_float) -> c_float = c_float_utils:: hypot,
98
+ fn ldexp( x: c_float, n: c_int) -> c_float = c_float_utils:: ldexp,
99
+ fn lgamma( n: c_float, sign: & mut c_int) -> c_float = c_float_utils:: lgamma,
100
+ fn log_radix( n: c_float) -> c_float = c_float_utils:: log_radix,
101
+ fn ln1p( n: c_float) -> c_float = c_float_utils:: ln1p,
102
+ fn ilog_radix( n: c_float) -> c_int = c_float_utils:: ilog_radix,
103
+ fn modf( n: c_float, iptr: & mut c_float) -> c_float = c_float_utils:: modf,
104
+ fn round( n: c_float) -> c_float = c_float_utils:: round,
105
+ fn ldexp_radix( n: c_float, i: c_int) -> c_float = c_float_utils:: ldexp_radix,
106
+ fn sinh( n: c_float) -> c_float = c_float_utils:: sinh,
107
+ fn tan( n: c_float) -> c_float = c_float_utils:: tan,
108
+ fn tanh( n: c_float) -> c_float = c_float_utils:: tanh,
109
+ fn tgamma( n: c_float) -> c_float = c_float_utils:: tgamma)
110
+
100
111
101
112
// These are not defined inside consts:: for consistency with
102
113
// the integer types
@@ -143,9 +154,6 @@ pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
143
154
#[ inline( always) ]
144
155
pub fn gt ( x : f32 , y : f32 ) -> bool { return x > y; }
145
156
146
- /// Returns `x` rounded down
147
- #[ inline( always) ]
148
- pub fn floor ( x : f32 ) -> f32 { unsafe { floorf32 ( x) } }
149
157
150
158
// FIXME (#1999): replace the predicates below with llvm intrinsics or
151
159
// calls to the libmath macros in the rust runtime for performance.
0 commit comments