10
10
11
11
//! Operations and constants for `f64`
12
12
13
+ use cmath;
14
+ use libc:: { c_double, c_int} ;
13
15
use num:: strconv;
14
16
use num;
15
17
use option:: Option ;
18
+ use unstable:: intrinsics:: floorf64;
16
19
use to_str;
17
20
use from_str;
18
21
@@ -22,98 +25,87 @@ use from_str;
22
25
pub use cmath:: c_double_targ_consts:: * ;
23
26
pub use cmp:: { min, max} ;
24
27
25
- // An inner module is required to get the #[inline(always)] attribute on the
26
- // functions.
27
- pub use self :: delegated:: * ;
28
-
29
28
macro_rules! delegate(
30
29
(
31
- $(
32
- fn $name: ident(
33
- $(
34
- $arg: ident : $arg_ty: ty
35
- ) ,*
36
- ) -> $rv: ty = $bound_name: path
37
- ) ,*
38
- ) => (
39
- mod delegated {
40
- use cmath:: c_double_utils;
41
- use libc:: { c_double, c_int} ;
42
- use unstable:: intrinsics;
43
-
30
+ fn $name: ident(
44
31
$(
45
- #[ inline( always) ]
46
- pub fn $name( $( $arg : $arg_ty ) ,* ) -> $rv {
47
- unsafe {
48
- $bound_name( $( $arg ) ,* )
49
- }
50
- }
51
- ) *
32
+ $arg: ident : $arg_ty: ty
33
+ ) ,*
34
+ ) -> $rv: ty = $bound_name: path
35
+ ) => (
36
+ pub fn $name( $( $arg : $arg_ty ) ,* ) -> $rv {
37
+ unsafe {
38
+ $bound_name( $( $arg ) ,* )
39
+ }
52
40
}
53
41
)
54
42
)
55
43
56
- delegate ! (
57
- // intrinsics
58
- fn abs( n: f64 ) -> f64 = intrinsics:: fabsf64,
59
- fn cos( n: f64 ) -> f64 = intrinsics:: cosf64,
60
- fn exp( n: f64 ) -> f64 = intrinsics:: expf64,
61
- fn exp2( n: f64 ) -> f64 = intrinsics:: exp2f64,
62
- fn floor( x: f64 ) -> f64 = intrinsics:: floorf64,
63
- fn ln( n: f64 ) -> f64 = intrinsics:: logf64,
64
- fn log10( n: f64 ) -> f64 = intrinsics:: log10f64,
65
- fn log2( n: f64 ) -> f64 = intrinsics:: log2f64,
66
- fn mul_add( a: f64 , b: f64 , c: f64 ) -> f64 = intrinsics:: fmaf64,
67
- fn pow( n: f64 , e: f64 ) -> f64 = intrinsics:: powf64,
68
- fn powi( n: f64 , e: c_int) -> f64 = intrinsics:: powif64,
69
- fn sin( n: f64 ) -> f64 = intrinsics:: sinf64,
70
- fn sqrt( n: f64 ) -> f64 = intrinsics:: sqrtf64,
71
-
72
- // LLVM 3.3 required to use intrinsics for these four
73
- fn ceil( n: c_double) -> c_double = c_double_utils:: ceil,
74
- fn trunc( n: c_double) -> c_double = c_double_utils:: trunc,
75
- /*
76
- fn ceil(n: f64) -> f64 = intrinsics::ceilf64,
77
- fn trunc(n: f64) -> f64 = intrinsics::truncf64,
78
- fn rint(n: c_double) -> c_double = intrinsics::rintf64,
79
- fn nearbyint(n: c_double) -> c_double = intrinsics::nearbyintf64,
80
- */
81
-
82
- // cmath
83
- fn acos( n: c_double) -> c_double = c_double_utils:: acos,
84
- fn asin( n: c_double) -> c_double = c_double_utils:: asin,
85
- fn atan( n: c_double) -> c_double = c_double_utils:: atan,
86
- fn atan2( a: c_double, b: c_double) -> c_double = c_double_utils:: atan2,
87
- fn cbrt( n: c_double) -> c_double = c_double_utils:: cbrt,
88
- fn copysign( x: c_double, y: c_double) -> c_double = c_double_utils:: copysign,
89
- fn cosh( n: c_double) -> c_double = c_double_utils:: cosh,
90
- fn erf( n: c_double) -> c_double = c_double_utils:: erf,
91
- fn erfc( n: c_double) -> c_double = c_double_utils:: erfc,
92
- fn expm1( n: c_double) -> c_double = c_double_utils:: expm1,
93
- fn abs_sub( a: c_double, b: c_double) -> c_double = c_double_utils:: abs_sub,
94
- fn fmax( a: c_double, b: c_double) -> c_double = c_double_utils:: fmax,
95
- fn fmin( a: c_double, b: c_double) -> c_double = c_double_utils:: fmin,
96
- fn nextafter( x: c_double, y: c_double) -> c_double = c_double_utils:: nextafter,
97
- fn frexp( n: c_double, value: & mut c_int) -> c_double = c_double_utils:: frexp,
98
- fn hypot( x: c_double, y: c_double) -> c_double = c_double_utils:: hypot,
99
- fn ldexp( x: c_double, n: c_int) -> c_double = c_double_utils:: ldexp,
100
- fn lgamma( n: c_double, sign: & mut c_int) -> c_double = c_double_utils:: lgamma,
101
- fn log_radix( n: c_double) -> c_double = c_double_utils:: log_radix,
102
- fn ln1p( n: c_double) -> c_double = c_double_utils:: ln1p,
103
- fn ilog_radix( n: c_double) -> c_int = c_double_utils:: ilog_radix,
104
- fn modf( n: c_double, iptr: & mut c_double) -> c_double = c_double_utils:: modf,
105
- fn round( n: c_double) -> c_double = c_double_utils:: round,
106
- fn ldexp_radix( n: c_double, i: c_int) -> c_double = c_double_utils:: ldexp_radix,
107
- fn sinh( n: c_double) -> c_double = c_double_utils:: sinh,
108
- fn tan( n: c_double) -> c_double = c_double_utils:: tan,
109
- fn tanh( n: c_double) -> c_double = c_double_utils:: tanh,
110
- fn tgamma( n: c_double) -> c_double = c_double_utils:: tgamma,
111
- fn j0( n: c_double) -> c_double = c_double_utils:: j0,
112
- fn j1( n: c_double) -> c_double = c_double_utils:: j1,
113
- fn jn( i: c_int, n: c_double) -> c_double = c_double_utils:: jn,
114
- fn y0( n: c_double) -> c_double = c_double_utils:: y0,
115
- fn y1( n: c_double) -> c_double = c_double_utils:: y1,
116
- fn yn( i: c_int, n: c_double) -> c_double = c_double_utils:: yn)
44
+ delegate ! ( fn acos( n: c_double) -> c_double = cmath:: c_double_utils:: acos)
45
+ delegate ! ( fn asin( n: c_double) -> c_double = cmath:: c_double_utils:: asin)
46
+ delegate ! ( fn atan( n: c_double) -> c_double = cmath:: c_double_utils:: atan)
47
+ delegate ! ( fn atan2( a: c_double, b: c_double) -> c_double =
48
+ cmath:: c_double_utils:: atan2)
49
+ delegate ! ( fn cbrt( n: c_double) -> c_double = cmath:: c_double_utils:: cbrt)
50
+ delegate ! ( fn ceil( n: c_double) -> c_double = cmath:: c_double_utils:: ceil)
51
+ delegate ! ( fn copysign( x: c_double, y: c_double) -> c_double =
52
+ cmath:: c_double_utils:: copysign)
53
+ delegate ! ( fn cos( n: c_double) -> c_double = cmath:: c_double_utils:: cos)
54
+ delegate ! ( fn cosh( n: c_double) -> c_double = cmath:: c_double_utils:: cosh)
55
+ delegate ! ( fn erf( n: c_double) -> c_double = cmath:: c_double_utils:: erf)
56
+ delegate ! ( fn erfc( n: c_double) -> c_double = cmath:: c_double_utils:: erfc)
57
+ delegate ! ( fn exp( n: c_double) -> c_double = cmath:: c_double_utils:: exp)
58
+ delegate ! ( fn expm1( n: c_double) -> c_double = cmath:: c_double_utils:: expm1)
59
+ delegate ! ( fn exp2( n: c_double) -> c_double = cmath:: c_double_utils:: exp2)
60
+ delegate ! ( fn abs( n: c_double) -> c_double = cmath:: c_double_utils:: abs)
61
+ delegate ! ( fn abs_sub( a: c_double, b: c_double) -> c_double =
62
+ cmath:: c_double_utils:: abs_sub)
63
+ delegate ! ( fn mul_add( a: c_double, b: c_double, c: c_double) -> c_double =
64
+ cmath:: c_double_utils:: mul_add)
65
+ delegate ! ( fn fmax( a: c_double, b: c_double) -> c_double =
66
+ cmath:: c_double_utils:: fmax)
67
+ delegate ! ( fn fmin( a: c_double, b: c_double) -> c_double =
68
+ cmath:: c_double_utils:: fmin)
69
+ delegate ! ( fn nextafter( x: c_double, y: c_double) -> c_double =
70
+ cmath:: c_double_utils:: nextafter)
71
+ delegate ! ( fn frexp( n: c_double, value: & mut c_int) -> c_double =
72
+ cmath:: c_double_utils:: frexp)
73
+ delegate ! ( fn hypot( x: c_double, y: c_double) -> c_double =
74
+ cmath:: c_double_utils:: hypot)
75
+ delegate ! ( fn ldexp( x: c_double, n: c_int) -> c_double =
76
+ cmath:: c_double_utils:: ldexp)
77
+ delegate ! ( fn lgamma( n: c_double, sign: & mut c_int) -> c_double =
78
+ cmath:: c_double_utils:: lgamma)
79
+ delegate ! ( fn ln( n: c_double) -> c_double = cmath:: c_double_utils:: ln)
80
+ delegate ! ( fn log_radix( n: c_double) -> c_double =
81
+ cmath:: c_double_utils:: log_radix)
82
+ delegate ! ( fn ln1p( n: c_double) -> c_double = cmath:: c_double_utils:: ln1p)
83
+ delegate ! ( fn log10( n: c_double) -> c_double = cmath:: c_double_utils:: log10)
84
+ delegate ! ( fn log2( n: c_double) -> c_double = cmath:: c_double_utils:: log2)
85
+ delegate ! ( fn ilog_radix( n: c_double) -> c_int =
86
+ cmath:: c_double_utils:: ilog_radix)
87
+ delegate ! ( fn modf( n: c_double, iptr: & mut c_double) -> c_double =
88
+ cmath:: c_double_utils:: modf)
89
+ delegate ! ( fn pow( n: c_double, e: c_double) -> c_double =
90
+ cmath:: c_double_utils:: pow)
91
+ delegate ! ( fn round( n: c_double) -> c_double = cmath:: c_double_utils:: round)
92
+ delegate ! ( fn ldexp_radix( n: c_double, i: c_int) -> c_double =
93
+ cmath:: c_double_utils:: ldexp_radix)
94
+ delegate ! ( fn sin( n: c_double) -> c_double = cmath:: c_double_utils:: sin)
95
+ delegate ! ( fn sinh( n: c_double) -> c_double = cmath:: c_double_utils:: sinh)
96
+ delegate ! ( fn sqrt( n: c_double) -> c_double = cmath:: c_double_utils:: sqrt)
97
+ delegate ! ( fn tan( n: c_double) -> c_double = cmath:: c_double_utils:: tan)
98
+ delegate ! ( fn tanh( n: c_double) -> c_double = cmath:: c_double_utils:: tanh)
99
+ delegate ! ( fn tgamma( n: c_double) -> c_double = cmath:: c_double_utils:: tgamma)
100
+ delegate ! ( fn trunc( n: c_double) -> c_double = cmath:: c_double_utils:: trunc)
101
+ delegate ! ( fn j0( n: c_double) -> c_double = cmath:: c_double_utils:: j0)
102
+ delegate ! ( fn j1( n: c_double) -> c_double = cmath:: c_double_utils:: j1)
103
+ delegate ! ( fn jn( i: c_int, n: c_double) -> c_double =
104
+ cmath:: c_double_utils:: jn)
105
+ delegate ! ( fn y0( n: c_double) -> c_double = cmath:: c_double_utils:: y0)
106
+ delegate ! ( fn y1( n: c_double) -> c_double = cmath:: c_double_utils:: y1)
107
+ delegate ! ( fn yn( i: c_int, n: c_double) -> c_double =
108
+ cmath:: c_double_utils:: yn)
117
109
118
110
// FIXME (#1433): obtain these in a different way
119
111
@@ -226,6 +218,9 @@ pub fn is_finite(x: f64) -> bool {
226
218
return !( is_NaN ( x) || is_infinite ( x) ) ;
227
219
}
228
220
221
+ /// Returns `x` rounded down
222
+ #[ inline( always) ]
223
+ pub fn floor ( x : f64 ) -> f64 { unsafe { floorf64 ( x) } }
229
224
230
225
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
231
226
0 commit comments