@@ -162,13 +162,13 @@ pub trait Signed: Num + Neg<Self> {
162
162
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`.
163
163
///
164
164
/// For signed integers, `::MIN` will be returned if the number is `::MIN`.
165
- fn abs ( & self ) -> Self ;
165
+ fn abs ( self ) -> Self ;
166
166
167
167
/// The positive difference of two numbers.
168
168
///
169
169
/// Returns `zero` if the number is less than or equal to `other`, otherwise the difference
170
170
/// between `self` and `other` is returned.
171
- fn abs_sub ( & self , other : & Self ) -> Self ;
171
+ fn abs_sub ( self , other : Self ) -> Self ;
172
172
173
173
/// Returns the sign of the number.
174
174
///
@@ -183,64 +183,64 @@ pub trait Signed: Num + Neg<Self> {
183
183
/// * `0` if the number is zero
184
184
/// * `1` if the number is positive
185
185
/// * `-1` if the number is negative
186
- fn signum ( & self ) -> Self ;
186
+ fn signum ( self ) -> Self ;
187
187
188
188
/// Returns true if the number is positive and false if the number is zero or negative.
189
- fn is_positive ( & self ) -> bool ;
189
+ fn is_positive ( self ) -> bool ;
190
190
191
191
/// Returns true if the number is negative and false if the number is zero or positive.
192
- fn is_negative ( & self ) -> bool ;
192
+ fn is_negative ( self ) -> bool ;
193
193
}
194
194
195
195
macro_rules! signed_impl(
196
- ( $( $t : ty) * ) => ( $(
197
- impl Signed for $t {
196
+ ( $( $T : ty) * ) => ( $(
197
+ impl Signed for $T {
198
198
#[ inline]
199
- fn abs( & self ) -> $t {
200
- if self . is_negative( ) { -* self } else { * self }
199
+ fn abs( self ) -> $T {
200
+ if self . is_negative( ) { -self } else { self }
201
201
}
202
202
203
203
#[ inline]
204
- fn abs_sub( & self , other: & $t ) -> $t {
205
- if * self <= * other { 0 } else { * self - * other }
204
+ fn abs_sub( self , other: $T ) -> $T {
205
+ if self <= other { 0 } else { self - other }
206
206
}
207
207
208
208
#[ inline]
209
- fn signum( & self ) -> $t {
210
- match * self {
209
+ fn signum( self ) -> $T {
210
+ match self {
211
211
n if n > 0 => 1 ,
212
212
0 => 0 ,
213
213
_ => -1 ,
214
214
}
215
215
}
216
216
217
217
#[ inline]
218
- fn is_positive( & self ) -> bool { * self > 0 }
218
+ fn is_positive( self ) -> bool { self > 0 }
219
219
220
220
#[ inline]
221
- fn is_negative( & self ) -> bool { * self < 0 }
221
+ fn is_negative( self ) -> bool { self < 0 }
222
222
}
223
223
) * )
224
224
)
225
225
226
226
signed_impl ! ( int i8 i16 i32 i64 )
227
227
228
228
macro_rules! signed_float_impl(
229
- ( $t : ty, $nan: expr, $inf: expr, $neg_inf: expr, $fabs: path, $fcopysign: path, $fdim: ident) => {
230
- impl Signed for $t {
229
+ ( $T : ty, $nan: expr, $inf: expr, $neg_inf: expr, $fabs: path, $fcopysign: path, $fdim: ident) => {
230
+ impl Signed for $T {
231
231
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
232
232
#[ inline]
233
- fn abs( & self ) -> $t {
234
- unsafe { $fabs( * self ) }
233
+ fn abs( self ) -> $T {
234
+ unsafe { $fabs( self ) }
235
235
}
236
236
237
237
/// The positive difference of two numbers. Returns `0.0` if the number is
238
238
/// less than or equal to `other`, otherwise the difference between`self`
239
239
/// and `other` is returned.
240
240
#[ inline]
241
- fn abs_sub( & self , other: & $t ) -> $t {
242
- extern { fn $fdim( a: $t , b: $t ) -> $t ; }
243
- unsafe { $fdim( * self , * other) }
241
+ fn abs_sub( self , other: $T ) -> $T {
242
+ extern { fn $fdim( a: $T , b: $T ) -> $T ; }
243
+ unsafe { $fdim( self , other) }
244
244
}
245
245
246
246
/// # Returns
@@ -249,19 +249,19 @@ macro_rules! signed_float_impl(
249
249
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
250
250
/// - `NAN` if the number is NaN
251
251
#[ inline]
252
- fn signum( & self ) -> $t {
252
+ fn signum( self ) -> $T {
253
253
if self != self { $nan } else {
254
- unsafe { $fcopysign( 1.0 , * self ) }
254
+ unsafe { $fcopysign( 1.0 , self ) }
255
255
}
256
256
}
257
257
258
258
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
259
259
#[ inline]
260
- fn is_positive( & self ) -> bool { * self > 0.0 || ( 1.0 / * self ) == $inf }
260
+ fn is_positive( self ) -> bool { self > 0.0 || ( 1.0 / self ) == $inf }
261
261
262
262
/// Returns `true` if the number is negative, including `-0.0` and `NEG_INFINITY`
263
263
#[ inline]
264
- fn is_negative( & self ) -> bool { * self < 0.0 || ( 1.0 / * self ) == $neg_inf }
264
+ fn is_negative( self ) -> bool { self < 0.0 || ( 1.0 / self ) == $neg_inf }
265
265
}
266
266
}
267
267
)
@@ -287,7 +287,7 @@ pub fn abs<T: Signed>(value: T) -> T {
287
287
/// between `x` and `y` is returned.
288
288
#[ inline( always) ]
289
289
pub fn abs_sub < T : Signed > ( x : T , y : T ) -> T {
290
- x. abs_sub ( & y)
290
+ x. abs_sub ( y)
291
291
}
292
292
293
293
/// Returns the sign of the number.
0 commit comments