15
15
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
16
16
#![ allow( missing_docs) ]
17
17
18
+ #[ allow( unused_imports) ]
19
+ use sys;
20
+
18
21
#[ cfg( not( test) ) ]
19
22
use core:: num;
20
23
#[ cfg( not( test) ) ]
@@ -40,6 +43,8 @@ pub use core::f32::consts;
40
43
mod cmath {
41
44
use libc:: { c_float, c_int} ;
42
45
46
+ pub use sys:: f32:: cmath:: * ;
47
+
43
48
extern {
44
49
pub fn cbrtf ( n : c_float ) -> c_float ;
45
50
pub fn erff ( n : c_float ) -> c_float ;
@@ -55,88 +60,6 @@ mod cmath {
55
60
pub fn modff ( n : c_float , iptr : & mut c_float ) -> c_float ;
56
61
pub fn nextafterf ( x : c_float , y : c_float ) -> c_float ;
57
62
pub fn tgammaf ( n : c_float ) -> c_float ;
58
-
59
- #[ cfg_attr( all( windows, target_env = "msvc" ) , link_name = "__lgammaf_r" ) ]
60
- pub fn lgammaf_r ( n : c_float , sign : & mut c_int ) -> c_float ;
61
- #[ cfg_attr( all( windows, target_env = "msvc" ) , link_name = "_hypotf" ) ]
62
- pub fn hypotf ( x : c_float , y : c_float ) -> c_float ;
63
- }
64
-
65
- // See the comments in the `floor` function for why MSVC is special
66
- // here.
67
- #[ cfg( not( target_env = "msvc" ) ) ]
68
- extern {
69
- pub fn acosf ( n : c_float ) -> c_float ;
70
- pub fn asinf ( n : c_float ) -> c_float ;
71
- pub fn atan2f ( a : c_float , b : c_float ) -> c_float ;
72
- pub fn atanf ( n : c_float ) -> c_float ;
73
- pub fn coshf ( n : c_float ) -> c_float ;
74
- pub fn frexpf ( n : c_float , value : & mut c_int ) -> c_float ;
75
- pub fn ldexpf ( x : c_float , n : c_int ) -> c_float ;
76
- pub fn sinhf ( n : c_float ) -> c_float ;
77
- pub fn tanf ( n : c_float ) -> c_float ;
78
- pub fn tanhf ( n : c_float ) -> c_float ;
79
- }
80
-
81
- #[ cfg( target_env = "msvc" ) ]
82
- pub use self :: shims:: * ;
83
- #[ cfg( target_env = "msvc" ) ]
84
- mod shims {
85
- use libc:: { c_float, c_int} ;
86
-
87
- #[ inline]
88
- pub unsafe fn acosf ( n : c_float ) -> c_float {
89
- f64:: acos ( n as f64 ) as c_float
90
- }
91
-
92
- #[ inline]
93
- pub unsafe fn asinf ( n : c_float ) -> c_float {
94
- f64:: asin ( n as f64 ) as c_float
95
- }
96
-
97
- #[ inline]
98
- pub unsafe fn atan2f ( n : c_float , b : c_float ) -> c_float {
99
- f64:: atan2 ( n as f64 , b as f64 ) as c_float
100
- }
101
-
102
- #[ inline]
103
- pub unsafe fn atanf ( n : c_float ) -> c_float {
104
- f64:: atan ( n as f64 ) as c_float
105
- }
106
-
107
- #[ inline]
108
- pub unsafe fn coshf ( n : c_float ) -> c_float {
109
- f64:: cosh ( n as f64 ) as c_float
110
- }
111
-
112
- #[ inline]
113
- #[ allow( deprecated) ]
114
- pub unsafe fn frexpf ( x : c_float , value : & mut c_int ) -> c_float {
115
- let ( a, b) = f64:: frexp ( x as f64 ) ;
116
- * value = b as c_int ;
117
- a as c_float
118
- }
119
-
120
- #[ inline]
121
- #[ allow( deprecated) ]
122
- pub unsafe fn ldexpf ( x : c_float , n : c_int ) -> c_float {
123
- f64:: ldexp ( x as f64 , n as isize ) as c_float
124
- }
125
-
126
- #[ inline]
127
- pub unsafe fn sinhf ( n : c_float ) -> c_float {
128
- f64:: sinh ( n as f64 ) as c_float
129
- }
130
-
131
- #[ inline]
132
- pub unsafe fn tanf ( n : c_float ) -> c_float {
133
- f64:: tan ( n as f64 ) as c_float
134
- }
135
-
136
- #[ inline]
137
- pub unsafe fn tanhf ( n : c_float ) -> c_float {
138
- f64:: tanh ( n as f64 ) as c_float
139
- }
140
63
}
141
64
}
142
65
@@ -301,10 +224,7 @@ impl f32 {
301
224
// Note that there are many MSVC-specific float operations which
302
225
// redirect to this comment, so `floorf` is just one case of a missing
303
226
// function on MSVC, but there are many others elsewhere.
304
- #[ cfg( target_env = "msvc" ) ]
305
- return ( self as f64 ) . floor ( ) as f32 ;
306
- #[ cfg( not( target_env = "msvc" ) ) ]
307
- return unsafe { intrinsics:: floorf32 ( self ) } ;
227
+ sys:: f32:: floor ( self )
308
228
}
309
229
310
230
/// Returns the smallest integer greater than or equal to a number.
@@ -320,10 +240,7 @@ impl f32 {
320
240
#[ inline]
321
241
pub fn ceil ( self ) -> f32 {
322
242
// see notes above in `floor`
323
- #[ cfg( target_env = "msvc" ) ]
324
- return ( self as f64 ) . ceil ( ) as f32 ;
325
- #[ cfg( not( target_env = "msvc" ) ) ]
326
- return unsafe { intrinsics:: ceilf32 ( self ) } ;
243
+ sys:: f32:: ceil ( self )
327
244
}
328
245
329
246
/// Returns the nearest integer to a number. Round half-way cases away from
@@ -519,10 +436,7 @@ impl f32 {
519
436
#[ inline]
520
437
pub fn powf ( self , n : f32 ) -> f32 {
521
438
// see notes above in `floor`
522
- #[ cfg( target_env = "msvc" ) ]
523
- return ( self as f64 ) . powf ( n as f64 ) as f32 ;
524
- #[ cfg( not( target_env = "msvc" ) ) ]
525
- return unsafe { intrinsics:: powf32 ( self , n) } ;
439
+ sys:: f32:: powf ( self , n)
526
440
}
527
441
528
442
/// Takes the square root of a number.
@@ -568,10 +482,7 @@ impl f32 {
568
482
#[ inline]
569
483
pub fn exp ( self ) -> f32 {
570
484
// see notes above in `floor`
571
- #[ cfg( target_env = "msvc" ) ]
572
- return ( self as f64 ) . exp ( ) as f32 ;
573
- #[ cfg( not( target_env = "msvc" ) ) ]
574
- return unsafe { intrinsics:: expf32 ( self ) } ;
485
+ sys:: f32:: exp ( self )
575
486
}
576
487
577
488
/// Returns `2^(self)`.
@@ -610,10 +521,7 @@ impl f32 {
610
521
#[ inline]
611
522
pub fn ln ( self ) -> f32 {
612
523
// see notes above in `floor`
613
- #[ cfg( target_env = "msvc" ) ]
614
- return ( self as f64 ) . ln ( ) as f32 ;
615
- #[ cfg( not( target_env = "msvc" ) ) ]
616
- return unsafe { intrinsics:: logf32 ( self ) } ;
524
+ sys:: f32:: ln ( self )
617
525
}
618
526
619
527
/// Returns the logarithm of the number with respect to an arbitrary base.
@@ -652,10 +560,7 @@ impl f32 {
652
560
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
653
561
#[ inline]
654
562
pub fn log2 ( self ) -> f32 {
655
- #[ cfg( target_os = "android" ) ]
656
- return :: sys:: android:: log2f32 ( self ) ;
657
- #[ cfg( not( target_os = "android" ) ) ]
658
- return unsafe { intrinsics:: log2f32 ( self ) } ;
563
+ sys:: f32:: log2 ( self )
659
564
}
660
565
661
566
/// Returns the base 10 logarithm of the number.
@@ -674,10 +579,7 @@ impl f32 {
674
579
#[ inline]
675
580
pub fn log10 ( self ) -> f32 {
676
581
// see notes above in `floor`
677
- #[ cfg( target_env = "msvc" ) ]
678
- return ( self as f64 ) . log10 ( ) as f32 ;
679
- #[ cfg( not( target_env = "msvc" ) ) ]
680
- return unsafe { intrinsics:: log10f32 ( self ) } ;
582
+ sys:: f32:: log10 ( self )
681
583
}
682
584
683
585
/// Converts radians to degrees.
@@ -908,10 +810,7 @@ impl f32 {
908
810
#[ inline]
909
811
pub fn sin ( self ) -> f32 {
910
812
// see notes in `core::f32::Float::floor`
911
- #[ cfg( target_env = "msvc" ) ]
912
- return ( self as f64 ) . sin ( ) as f32 ;
913
- #[ cfg( not( target_env = "msvc" ) ) ]
914
- return unsafe { intrinsics:: sinf32 ( self ) } ;
813
+ sys:: f32:: sin ( self )
915
814
}
916
815
917
816
/// Computes the cosine of a number (in radians).
@@ -929,10 +828,7 @@ impl f32 {
929
828
#[ inline]
930
829
pub fn cos ( self ) -> f32 {
931
830
// see notes in `core::f32::Float::floor`
932
- #[ cfg( target_env = "msvc" ) ]
933
- return ( self as f64 ) . cos ( ) as f32 ;
934
- #[ cfg( not( target_env = "msvc" ) ) ]
935
- return unsafe { intrinsics:: cosf32 ( self ) } ;
831
+ sys:: f32:: cos ( self )
936
832
}
937
833
938
834
/// Computes the tangent of a number (in radians).
0 commit comments