@@ -62,71 +62,77 @@ pub trait NumStrConv {
62
62
63
63
}
64
64
65
- macro_rules! impl_NumStrConv_Floating (
66
- ( $t : ty ) => (
67
- impl NumStrConv for $t {
68
- static pure fn has_NaN ( ) -> bool { true }
69
- static pure fn has_inf ( ) -> bool { true }
70
- static pure fn has_neg_inf ( ) -> bool { true }
71
- static pure fn has_neg_zero ( ) -> bool { true }
72
-
73
- static pure fn NaN ( ) -> Option <$t> { Some ( 0.0 / 0.0 ) }
74
- static pure fn inf ( ) -> Option <$t> { Some ( 1.0 / 0.0 ) }
75
- static pure fn neg_inf ( ) -> Option <$t> { Some ( - 1.0 / 0.0 ) }
76
- static pure fn neg_zero ( ) -> Option <$t> { Some ( - 0.0 ) }
77
-
78
- pure fn is_NaN ( & self ) -> bool { * self != * self }
79
-
80
- pure fn is_inf ( & self ) -> bool {
81
- * self == NumStrConv :: inf ( ) . unwrap ( )
82
- }
83
-
84
- pure fn is_neg_inf ( & self ) -> bool {
85
- * self == NumStrConv :: neg_inf ( ) . unwrap( )
86
- }
65
+ macro_rules! impl_NumStrConv_Floating ( ( $t : ty ) => (
66
+ impl NumStrConv for $t {
67
+ # [ inline ( always ) ] static pure fn has_NaN ( ) -> bool { true }
68
+ # [ inline ( always ) ] static pure fn has_inf ( ) -> bool { true }
69
+ # [ inline ( always ) ] static pure fn has_neg_inf ( ) -> bool { true }
70
+ # [ inline ( always ) ] static pure fn has_neg_zero ( ) -> bool { true }
71
+
72
+ # [ inline ( always ) ]
73
+ static pure fn NaN ( ) -> Option <$t> { Some ( 0.0 / 0.0 ) }
74
+ # [ inline ( always ) ]
75
+ static pure fn inf ( ) -> Option <$t> { Some ( 1.0 / 0.0 ) }
76
+ # [ inline ( always ) ]
77
+ static pure fn neg_inf ( ) -> Option <$t> { Some ( - 1.0 / 0.0 ) }
78
+ # [ inline ( always ) ]
79
+ static pure fn neg_zero ( ) -> Option <$t> { Some ( - 0.0 ) }
80
+
81
+ # [ inline ( always ) ] pure fn is_NaN ( & self ) -> bool { * self != * self }
82
+
83
+ # [ inline ( always ) ]
84
+ pure fn is_inf ( & self ) -> bool {
85
+ * self == NumStrConv :: inf ( ) . unwrap( )
86
+ }
87
87
88
- pure fn is_neg_zero( & self ) -> bool {
89
- * self == 0.0 && ( 1.0 / * self ) . is_neg_inf( )
90
- }
88
+ #[ inline( always) ]
89
+ pure fn is_neg_inf( & self ) -> bool {
90
+ * self == NumStrConv :: neg_inf( ) . unwrap( )
91
+ }
91
92
92
- pure fn round_to_zero( & self ) -> $t {
93
- ( if * self < 0.0 { f64 :: ceil( * self as f64 ) }
94
- else { f64 :: floor( * self as f64 ) }
95
- ) as $t
96
- }
93
+ #[ inline( always) ]
94
+ pure fn is_neg_zero( & self ) -> bool {
95
+ * self == 0.0 && ( 1.0 / * self ) . is_neg_inf( )
96
+ }
97
97
98
- pure fn fractional_part( & self ) -> $t {
99
- * self - self . round_to_zero( )
100
- }
98
+ #[ inline( always) ]
99
+ pure fn round_to_zero( & self ) -> $t {
100
+ ( if * self < 0.0 { f64 :: ceil( * self as f64 ) }
101
+ else { f64 :: floor( * self as f64 ) }
102
+ ) as $t
101
103
}
102
- )
103
- )
104
-
105
- macro_rules! impl_NumStrConv_Integer (
106
- ( $t: ty) => (
107
- impl NumStrConv for $t {
108
- static pure fn has_NaN( ) -> bool { false }
109
- static pure fn has_inf( ) -> bool { false }
110
- static pure fn has_neg_inf( ) -> bool { false }
111
- static pure fn has_neg_zero( ) -> bool { false }
112
-
113
- static pure fn NaN ( ) -> Option <$t> { None }
114
- static pure fn inf( ) -> Option <$t> { None }
115
- static pure fn neg_inf( ) -> Option <$t> { None }
116
- static pure fn neg_zero( ) -> Option <$t> { None }
117
-
118
- pure fn is_NaN( & self ) -> bool { false }
119
- pure fn is_inf( & self ) -> bool { false }
120
- pure fn is_neg_inf( & self ) -> bool { false }
121
- pure fn is_neg_zero( & self ) -> bool { false }
122
-
123
- pure fn round_to_zero( & self ) -> $t { * self }
124
- pure fn fractional_part( & self ) -> $t { 0 }
104
+
105
+ #[ inline( always) ]
106
+ pure fn fractional_part( & self ) -> $t {
107
+ * self - self . round_to_zero( )
125
108
}
126
- )
127
- )
109
+ }
110
+ ) )
111
+
112
+ macro_rules! impl_NumStrConv_Integer ( ( $t: ty) => (
113
+ impl NumStrConv for $t {
114
+ #[ inline( always) ] static pure fn has_NaN( ) -> bool { false }
115
+ #[ inline( always) ] static pure fn has_inf( ) -> bool { false }
116
+ #[ inline( always) ] static pure fn has_neg_inf( ) -> bool { false }
117
+ #[ inline( always) ] static pure fn has_neg_zero( ) -> bool { false }
118
+
119
+ #[ inline( always) ] static pure fn NaN ( ) -> Option <$t> { None }
120
+ #[ inline( always) ] static pure fn inf( ) -> Option <$t> { None }
121
+ #[ inline( always) ] static pure fn neg_inf( ) -> Option <$t> { None }
122
+ #[ inline( always) ] static pure fn neg_zero( ) -> Option <$t> { None }
123
+
124
+ #[ inline( always) ] pure fn is_NaN( & self ) -> bool { false }
125
+ #[ inline( always) ] pure fn is_inf( & self ) -> bool { false }
126
+ #[ inline( always) ] pure fn is_neg_inf( & self ) -> bool { false }
127
+ #[ inline( always) ] pure fn is_neg_zero( & self ) -> bool { false }
128
+
129
+ #[ inline( always) ] pure fn round_to_zero( & self ) -> $t { * self }
130
+ #[ inline( always) ] pure fn fractional_part( & self ) -> $t { 0 }
131
+ }
132
+ ) )
128
133
129
- // XXX: Replace by two generic impls for traits 'Integral' and 'Floating'
134
+ // FIXME: #4955
135
+ // Replace by two generic impls for traits 'Integral' and 'Floating'
130
136
impl_NumStrConv_Floating ! ( float)
131
137
impl_NumStrConv_Floating ! ( f32 )
132
138
impl_NumStrConv_Floating ! ( f64 )
@@ -143,8 +149,6 @@ impl_NumStrConv_Integer!(u16)
143
149
impl_NumStrConv_Integer ! ( u32 )
144
150
impl_NumStrConv_Integer ! ( u64 )
145
151
146
- // NOTE: inline the methods
147
-
148
152
/**
149
153
* Converts a number to its string representation as a byte vector.
150
154
* This is meant to be a common base implementation for all numeric string
@@ -176,8 +180,8 @@ impl_NumStrConv_Integer!(u64)
176
180
* # Failure
177
181
* - Fails if `radix` < 2 or `radix` > 36.
178
182
*/
179
- pub pure fn to_str_bytes_common < T : NumCast +Zero +One +Eq +Ord +NumStrConv +Copy +Div < T , T > +
180
- Neg < T > +Modulo < T , T > +Mul < T , T > > (
183
+ pub pure fn to_str_bytes_common < T : NumCast +Zero +One +Eq +Ord +NumStrConv +Copy +
184
+ Div < T , T > + Neg < T > +Modulo < T , T > +Mul < T , T > > (
181
185
num : & T , radix : uint , negative_zero : bool ,
182
186
sign : SignFormat , digits : SignificantDigits ) -> ( ~[ u8 ] , bool ) {
183
187
if radix as int < 2 {
@@ -400,8 +404,8 @@ pub pure fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+Div<T,
400
404
* `to_str_bytes_common()`, for details see there.
401
405
*/
402
406
#[ inline( always) ]
403
- pub pure fn to_str_common < T : NumCast +Zero +One +Eq +Ord +NumStrConv +Copy +Div < T , T > + Neg < T >
404
- +Modulo < T , T > +Mul < T , T > > (
407
+ pub pure fn to_str_common < T : NumCast +Zero +One +Eq +Ord +NumStrConv +Copy +
408
+ Div < T , T > + Neg < T > +Modulo < T , T > +Mul < T , T > > (
405
409
num : & T , radix : uint , negative_zero : bool ,
406
410
sign : SignFormat , digits : SignificantDigits ) -> ( ~str , bool ) {
407
411
let ( bytes, special) = to_str_bytes_common ( num, radix,
@@ -457,7 +461,8 @@ priv const DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
457
461
* formated like `FF_AE_FF_FF`.
458
462
*/
459
463
pub pure fn from_str_bytes_common < T : NumCast +Zero +One +Ord +Copy +Div < T , T > +
460
- Mul < T , T > +Sub < T , T > +Neg < T > +Add < T , T > +NumStrConv > (
464
+ Mul < T , T > +Sub < T , T > +Neg < T > +Add < T , T > +
465
+ NumStrConv > (
461
466
buf : & [ u8 ] , radix : uint , negative : bool , fractional : bool ,
462
467
special : bool , exponent : ExponentFormat , empty_zero : bool
463
468
) -> Option < T > {
0 commit comments