18
18
use prelude:: v1:: * ;
19
19
20
20
use core:: num;
21
+ #[ cfg( not( target_env = "msvc" ) ) ]
21
22
use intrinsics;
22
23
use libc:: c_int;
23
24
use num:: { FpCategory , ParseFloatError } ;
@@ -33,12 +34,7 @@ mod cmath {
33
34
use libc:: { c_float, c_int} ;
34
35
35
36
extern {
36
- pub fn acosf ( n : c_float ) -> c_float ;
37
- pub fn asinf ( n : c_float ) -> c_float ;
38
- pub fn atanf ( n : c_float ) -> c_float ;
39
- pub fn atan2f ( a : c_float , b : c_float ) -> c_float ;
40
37
pub fn cbrtf ( n : c_float ) -> c_float ;
41
- pub fn coshf ( n : c_float ) -> c_float ;
42
38
pub fn erff ( n : c_float ) -> c_float ;
43
39
pub fn erfcf ( n : c_float ) -> c_float ;
44
40
pub fn expm1f ( n : c_float ) -> c_float ;
@@ -51,32 +47,77 @@ mod cmath {
51
47
pub fn log1pf ( n : c_float ) -> c_float ;
52
48
pub fn ilogbf ( n : c_float ) -> c_int ;
53
49
pub fn modff ( n : c_float , iptr : & mut c_float ) -> c_float ;
54
- pub fn sinhf ( n : c_float ) -> c_float ;
55
- pub fn tanf ( n : c_float ) -> c_float ;
56
- pub fn tanhf ( n : c_float ) -> c_float ;
57
50
pub fn tgammaf ( n : c_float ) -> c_float ;
58
51
59
52
#[ cfg_attr( all( windows, target_env = "msvc" ) , link_name = "__lgammaf_r" ) ]
60
53
pub fn lgammaf_r ( n : c_float , sign : & mut c_int ) -> c_float ;
61
54
#[ cfg_attr( all( windows, target_env = "msvc" ) , link_name = "_hypotf" ) ]
62
55
pub fn hypotf ( x : c_float , y : c_float ) -> c_float ;
56
+ }
63
57
64
- #[ cfg( any( unix, all( windows, not( target_env = "msvc" ) ) ) ) ]
58
+ // See the comments in `core::float::Float::floor` for why MSVC is special
59
+ // here.
60
+ #[ cfg( not( target_env = "msvc" ) ) ]
61
+ extern {
62
+ pub fn acosf ( n : c_float ) -> c_float ;
63
+ pub fn asinf ( n : c_float ) -> c_float ;
64
+ pub fn atan2f ( a : c_float , b : c_float ) -> c_float ;
65
+ pub fn atanf ( n : c_float ) -> c_float ;
66
+ pub fn coshf ( n : c_float ) -> c_float ;
65
67
pub fn frexpf ( n : c_float , value : & mut c_int ) -> c_float ;
66
- #[ cfg( any( unix, all( windows, not( target_env = "msvc" ) ) ) ) ]
67
68
pub fn ldexpf ( x : c_float , n : c_int ) -> c_float ;
69
+ pub fn sinhf ( n : c_float ) -> c_float ;
70
+ pub fn tanf ( n : c_float ) -> c_float ;
71
+ pub fn tanhf ( n : c_float ) -> c_float ;
68
72
}
69
73
70
- #[ cfg( all( windows, target_env = "msvc" ) ) ]
71
- pub unsafe fn ldexpf ( x : c_float , n : c_int ) -> c_float {
72
- f64:: ldexp ( x as f64 , n as isize ) as c_float
73
- }
74
+ #[ cfg( target_env = "msvc" ) ]
75
+ pub use self :: shims:: * ;
76
+ #[ cfg( target_env = "msvc" ) ]
77
+ mod shims {
78
+ use libc:: { c_float, c_int} ;
79
+
80
+ pub unsafe fn acosf ( n : c_float ) -> c_float {
81
+ f64:: acos ( n as f64 ) as c_float
82
+ }
83
+
84
+ pub unsafe fn asinf ( n : c_float ) -> c_float {
85
+ f64:: asin ( n as f64 ) as c_float
86
+ }
87
+
88
+ pub unsafe fn atan2f ( n : c_float , b : c_float ) -> c_float {
89
+ f64:: atan2 ( n as f64 , b as f64 ) as c_float
90
+ }
91
+
92
+ pub unsafe fn atanf ( n : c_float ) -> c_float {
93
+ f64:: atan ( n as f64 ) as c_float
94
+ }
95
+
96
+ pub unsafe fn coshf ( n : c_float ) -> c_float {
97
+ f64:: cosh ( n as f64 ) as c_float
98
+ }
99
+
100
+ pub unsafe fn frexpf ( x : c_float , value : & mut c_int ) -> c_float {
101
+ let ( a, b) = f64:: frexp ( x as f64 ) ;
102
+ * value = b as c_int ;
103
+ a as c_float
104
+ }
105
+
106
+ pub unsafe fn ldexpf ( x : c_float , n : c_int ) -> c_float {
107
+ f64:: ldexp ( x as f64 , n as isize ) as c_float
108
+ }
109
+
110
+ pub unsafe fn sinhf ( n : c_float ) -> c_float {
111
+ f64:: sinh ( n as f64 ) as c_float
112
+ }
74
113
75
- #[ cfg( all( windows, target_env = "msvc" ) ) ]
76
- pub unsafe fn frexpf ( x : c_float , value : & mut c_int ) -> c_float {
77
- let ( a, b) = f64:: frexp ( x as f64 ) ;
78
- * value = b as c_int ;
79
- a as c_float
114
+ pub unsafe fn tanf ( n : c_float ) -> c_float {
115
+ f64:: tan ( n as f64 ) as c_float
116
+ }
117
+
118
+ pub unsafe fn tanhf ( n : c_float ) -> c_float {
119
+ f64:: tanh ( n as f64 ) as c_float
120
+ }
80
121
}
81
122
}
82
123
@@ -761,7 +802,13 @@ impl f32 {
761
802
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
762
803
#[ inline]
763
804
pub fn sin ( self ) -> f32 {
764
- unsafe { intrinsics:: sinf32 ( self ) }
805
+ return sinf ( self ) ;
806
+
807
+ // see notes in `core::f32::Float::floor`
808
+ #[ cfg( target_env = "msvc" ) ]
809
+ fn sinf ( f : f32 ) -> f32 { ( f as f64 ) . sin ( ) as f32 }
810
+ #[ cfg( not( target_env = "msvc" ) ) ]
811
+ fn sinf ( f : f32 ) -> f32 { unsafe { intrinsics:: sinf32 ( f) } }
765
812
}
766
813
767
814
/// Computes the cosine of a number (in radians).
@@ -778,7 +825,13 @@ impl f32 {
778
825
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
779
826
#[ inline]
780
827
pub fn cos ( self ) -> f32 {
781
- unsafe { intrinsics:: cosf32 ( self ) }
828
+ return cosf ( self ) ;
829
+
830
+ // see notes in `core::f32::Float::floor`
831
+ #[ cfg( target_env = "msvc" ) ]
832
+ fn cosf ( f : f32 ) -> f32 { ( f as f64 ) . cos ( ) as f32 }
833
+ #[ cfg( not( target_env = "msvc" ) ) ]
834
+ fn cosf ( f : f32 ) -> f32 { unsafe { intrinsics:: cosf32 ( f) } }
782
835
}
783
836
784
837
/// Computes the tangent of a number (in radians).
0 commit comments