1515#![ stable( feature = "rust1" , since = "1.0.0" ) ]
1616#![ allow( missing_docs) ]
1717
18+ #[ allow( unused_imports) ]
19+ use sys;
20+
1821#[ cfg( not( test) ) ]
1922use core:: num;
2023#[ cfg( not( test) ) ]
@@ -40,6 +43,8 @@ pub use core::f32::consts;
4043mod cmath {
4144 use libc:: { c_float, c_int} ;
4245
46+ pub use sys:: f32:: cmath:: * ;
47+
4348 extern {
4449 pub fn cbrtf ( n : c_float ) -> c_float ;
4550 pub fn erff ( n : c_float ) -> c_float ;
@@ -55,88 +60,6 @@ mod cmath {
5560 pub fn modff ( n : c_float , iptr : & mut c_float ) -> c_float ;
5661 pub fn nextafterf ( x : c_float , y : c_float ) -> c_float ;
5762 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- }
14063 }
14164}
14265
@@ -301,10 +224,7 @@ impl f32 {
301224 // Note that there are many MSVC-specific float operations which
302225 // redirect to this comment, so `floorf` is just one case of a missing
303226 // 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 )
308228 }
309229
310230 /// Returns the smallest integer greater than or equal to a number.
@@ -320,10 +240,7 @@ impl f32 {
320240 #[ inline]
321241 pub fn ceil ( self ) -> f32 {
322242 // 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 )
327244 }
328245
329246 /// Returns the nearest integer to a number. Round half-way cases away from
@@ -519,10 +436,7 @@ impl f32 {
519436 #[ inline]
520437 pub fn powf ( self , n : f32 ) -> f32 {
521438 // 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)
526440 }
527441
528442 /// Takes the square root of a number.
@@ -568,10 +482,7 @@ impl f32 {
568482 #[ inline]
569483 pub fn exp ( self ) -> f32 {
570484 // 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 )
575486 }
576487
577488 /// Returns `2^(self)`.
@@ -610,10 +521,7 @@ impl f32 {
610521 #[ inline]
611522 pub fn ln ( self ) -> f32 {
612523 // 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 )
617525 }
618526
619527 /// Returns the logarithm of the number with respect to an arbitrary base.
@@ -652,10 +560,7 @@ impl f32 {
652560 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
653561 #[ inline]
654562 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 )
659564 }
660565
661566 /// Returns the base 10 logarithm of the number.
@@ -674,10 +579,7 @@ impl f32 {
674579 #[ inline]
675580 pub fn log10 ( self ) -> f32 {
676581 // 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 )
681583 }
682584
683585 /// Converts radians to degrees.
@@ -908,10 +810,7 @@ impl f32 {
908810 #[ inline]
909811 pub fn sin ( self ) -> f32 {
910812 // 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 )
915814 }
916815
917816 /// Computes the cosine of a number (in radians).
@@ -929,10 +828,7 @@ impl f32 {
929828 #[ inline]
930829 pub fn cos ( self ) -> f32 {
931830 // 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 )
936832 }
937833
938834 /// Computes the tangent of a number (in radians).
0 commit comments