Skip to content

Commit f0feced

Browse files
committed
---
yaml --- r: 159584 b: refs/heads/auto c: de938b6 h: refs/heads/master v: v3
1 parent d91b5db commit f0feced

File tree

27 files changed

+180
-131
lines changed

27 files changed

+180
-131
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: e965ba85ca689ad77f63b7f0af9d7e337dcb4825
13+
refs/heads/auto: de938b6ca1a2b6b6df65d5935c765a7c25fbce84
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ syn keyword rustTrait FromIterator IntoIterator Extend ExactSize
9797
syn keyword rustTrait Iterator DoubleEndedIterator
9898
syn keyword rustTrait RandomAccessIterator CloneableIterator
9999
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator
100-
syn keyword rustTrait NumCast Signed Int UnsignedInt Float
100+
syn keyword rustTrait NumCast Int SignedInt UnsignedInt Float
101101
syn keyword rustTrait FloatMath ToPrimitive FromPrimitive
102102
syn keyword rustTrait Box
103103
syn keyword rustTrait GenericPath Path PosixPath WindowsPath

branches/auto/src/libcore/cmp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
//! operators, you could do the following:
2020
//!
2121
//! ```rust
22+
//! use core::num::SignedInt;
23+
//!
2224
//! // Our type.
2325
//! struct SketchyNum {
2426
//! num : int

branches/auto/src/libcore/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl<'a, T> Pointer for &'a mut T {
620620
macro_rules! floating(($ty:ident) => {
621621
impl Float for $ty {
622622
fn fmt(&self, fmt: &mut Formatter) -> Result {
623-
use num::{Float, Signed};
623+
use num::Float;
624624

625625
let digits = match fmt.precision {
626626
Some(i) => float::DigExact(i),
@@ -641,7 +641,7 @@ macro_rules! floating(($ty:ident) => {
641641

642642
impl LowerExp for $ty {
643643
fn fmt(&self, fmt: &mut Formatter) -> Result {
644-
use num::{Float, Signed};
644+
use num::Float;
645645

646646
let digits = match fmt.precision {
647647
Some(i) => float::DigExact(i),
@@ -662,7 +662,7 @@ macro_rules! floating(($ty:ident) => {
662662

663663
impl UpperExp for $ty {
664664
fn fmt(&self, fmt: &mut Formatter) -> Result {
665-
use num::{Float, Signed};
665+
use num::Float;
666666

667667
let digits = match fmt.precision {
668668
Some(i) => float::DigExact(i),

branches/auto/src/libcore/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ pub trait Iterator<A> {
573573
/// # Example
574574
///
575575
/// ```rust
576+
/// use core::num::SignedInt;
577+
///
576578
/// let xs = [-3i, 0, 1, 5, -10];
577579
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
578580
/// ```
@@ -597,6 +599,8 @@ pub trait Iterator<A> {
597599
/// # Example
598600
///
599601
/// ```rust
602+
/// use core::num::SignedInt;
603+
///
600604
/// let xs = [-3i, 0, 1, 5, -10];
601605
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
602606
/// ```

branches/auto/src/libcore/num/f32.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,41 @@ impl Float for f32 {
242242
#[inline]
243243
fn fract(self) -> f32 { self - self.trunc() }
244244

245+
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
246+
/// number is `Float::nan()`.
247+
#[inline]
248+
fn abs(self) -> f32 {
249+
unsafe { intrinsics::fabsf32(self) }
250+
}
251+
252+
/// Returns a number that represents the sign of `self`.
253+
///
254+
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
255+
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
256+
/// - `Float::nan()` if the number is `Float::nan()`
257+
#[inline]
258+
fn signum(self) -> f32 {
259+
if self.is_nan() {
260+
Float::nan()
261+
} else {
262+
unsafe { intrinsics::copysignf32(1.0, self) }
263+
}
264+
}
265+
266+
/// Returns `true` if `self` is positive, including `+0.0` and
267+
/// `Float::infinity()`.
268+
#[inline]
269+
fn is_positive(self) -> bool {
270+
self > 0.0 || (1.0 / self) == Float::infinity()
271+
}
272+
273+
/// Returns `true` if `self` is negative, including `-0.0` and
274+
/// `Float::neg_infinity()`.
275+
#[inline]
276+
fn is_negative(self) -> bool {
277+
self < 0.0 || (1.0 / self) == Float::neg_infinity()
278+
}
279+
245280
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
246281
/// error. This produces a more accurate result with better performance than
247282
/// a separate multiplication operation followed by an add.
@@ -254,6 +289,7 @@ impl Float for f32 {
254289
#[inline]
255290
fn recip(self) -> f32 { 1.0 / self }
256291

292+
#[inline]
257293
fn powi(self, n: i32) -> f32 {
258294
unsafe { intrinsics::powif32(self, n) }
259295
}

branches/auto/src/libcore/num/f64.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,41 @@ impl Float for f64 {
248248
#[inline]
249249
fn fract(self) -> f64 { self - self.trunc() }
250250

251+
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
252+
/// number is `Float::nan()`.
253+
#[inline]
254+
fn abs(self) -> f64 {
255+
unsafe { intrinsics::fabsf64(self) }
256+
}
257+
258+
/// Returns a number that represents the sign of `self`.
259+
///
260+
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
261+
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
262+
/// - `Float::nan()` if the number is `Float::nan()`
263+
#[inline]
264+
fn signum(self) -> f64 {
265+
if self.is_nan() {
266+
Float::nan()
267+
} else {
268+
unsafe { intrinsics::copysignf64(1.0, self) }
269+
}
270+
}
271+
272+
/// Returns `true` if `self` is positive, including `+0.0` and
273+
/// `Float::infinity()`.
274+
#[inline]
275+
fn is_positive(self) -> bool {
276+
self > 0.0 || (1.0 / self) == Float::infinity()
277+
}
278+
279+
/// Returns `true` if `self` is negative, including `-0.0` and
280+
/// `Float::neg_infinity()`.
281+
#[inline]
282+
fn is_negative(self) -> bool {
283+
self < 0.0 || (1.0 / self) == Float::neg_infinity()
284+
}
285+
251286
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
252287
/// error. This produces a more accurate result with better performance than
253288
/// a separate multiplication operation followed by an add.

branches/auto/src/libcore/num/float_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
macro_rules! assert_approx_eq(
1515
($a:expr, $b:expr) => ({
16+
use num::Float;
1617
let (a, b) = (&$a, &$b);
1718
assert!((*a - *b).abs() < 1.0e-6,
1819
"{} is not approximately equal to {}", *a, *b);

branches/auto/src/libcore/num/mod.rs

Lines changed: 74 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -33,113 +33,6 @@ pub fn div_rem<T: Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
3333
(x / y, x % y)
3434
}
3535

36-
/// A built-in signed number.
37-
pub trait Signed: Neg<Self> {
38-
/// Computes the absolute value of `self`.
39-
fn abs(self) -> Self;
40-
41-
/// Returns a number (either `-1`, `0` or `1`) representing sign of `self`.
42-
fn signum(self) -> Self;
43-
44-
/// Returns `true` if `self` is a positive value.
45-
fn is_positive(self) -> bool;
46-
47-
/// Returns `true` if `self` is a negative value.
48-
fn is_negative(self) -> bool;
49-
}
50-
51-
macro_rules! signed_int_impl {
52-
($T:ty) => {
53-
impl Signed for $T {
54-
/// Computes the absolute value. `Int::min_value()` will be returned
55-
/// if the number is `Int::min_value()`.
56-
#[inline]
57-
fn abs(self) -> $T {
58-
if self.is_negative() { -self } else { self }
59-
}
60-
61-
/// # Returns
62-
///
63-
/// - `0` if the number is zero
64-
/// - `1` if the number is positive
65-
/// - `-1` if the number is negative
66-
#[inline]
67-
fn signum(self) -> $T {
68-
match self {
69-
n if n > 0 => 1,
70-
0 => 0,
71-
_ => -1,
72-
}
73-
}
74-
75-
/// Returns `true` if `self` is positive and `false` if the number
76-
/// is zero or negative.
77-
#[inline]
78-
fn is_positive(self) -> bool { self > 0 }
79-
80-
/// Returns `true` if `self` is negative and `false` if the number
81-
/// is zero or positive.
82-
#[inline]
83-
fn is_negative(self) -> bool { self < 0 }
84-
}
85-
}
86-
}
87-
88-
signed_int_impl!(i8)
89-
signed_int_impl!(i16)
90-
signed_int_impl!(i32)
91-
signed_int_impl!(i64)
92-
signed_int_impl!(int)
93-
94-
macro_rules! signed_float_impl {
95-
($T:ty, $fabs:path, $fcopysign:path) => {
96-
impl Signed for $T {
97-
/// Computes the absolute value. Returns `Float::nan()` if the
98-
/// number is `Float::nan()`.
99-
#[inline]
100-
fn abs(self) -> $T {
101-
unsafe { $fabs(self) }
102-
}
103-
104-
/// # Returns
105-
///
106-
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
107-
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
108-
/// - `Float::nan()` if the number is `Float::nan()`
109-
#[inline]
110-
fn signum(self) -> $T {
111-
if self.is_nan() {
112-
Float::nan()
113-
} else {
114-
unsafe { $fcopysign(1.0, self) }
115-
}
116-
}
117-
118-
/// Returns `true` if the number is positive, including `+0.0` and
119-
/// `Float::infinity()`.
120-
#[inline]
121-
fn is_positive(self) -> bool {
122-
self > 0.0 || (1.0 / self) == Float::infinity()
123-
}
124-
125-
/// Returns `true` if the number is negative, including `-0.0` and
126-
/// `Float::neg_infinity()`.
127-
#[inline]
128-
fn is_negative(self) -> bool {
129-
self < 0.0 || (1.0 / self) == Float::neg_infinity()
130-
}
131-
}
132-
};
133-
}
134-
135-
signed_float_impl!(f32,
136-
intrinsics::fabsf32,
137-
intrinsics::copysignf32)
138-
139-
signed_float_impl!(f64,
140-
intrinsics::fabsf64,
141-
intrinsics::copysignf64)
142-
14336
/// Raises a `base` to the power of `exp`, using exponentiation by squaring.
14437
///
14538
/// # Example
@@ -702,6 +595,63 @@ int_impl!(int = i64, u64, 64,
702595
intrinsics::i64_sub_with_overflow,
703596
intrinsics::i64_mul_with_overflow)
704597

598+
/// A built-in two's complement integer.
599+
pub trait SignedInt
600+
: Int
601+
+ Neg<Self>
602+
{
603+
/// Computes the absolute value of `self`. `Int::min_value()` will be
604+
/// returned if the number is `Int::min_value()`.
605+
fn abs(self) -> Self;
606+
607+
/// Returns a number representing sign of `self`.
608+
///
609+
/// - `0` if the number is zero
610+
/// - `1` if the number is positive
611+
/// - `-1` if the number is negative
612+
fn signum(self) -> Self;
613+
614+
/// Returns `true` if `self` is positive and `false` if the number
615+
/// is zero or negative.
616+
fn is_positive(self) -> bool;
617+
618+
/// Returns `true` if `self` is negative and `false` if the number
619+
/// is zero or positive.
620+
fn is_negative(self) -> bool;
621+
}
622+
623+
macro_rules! signed_int_impl {
624+
($T:ty) => {
625+
impl SignedInt for $T {
626+
#[inline]
627+
fn abs(self) -> $T {
628+
if self.is_negative() { -self } else { self }
629+
}
630+
631+
#[inline]
632+
fn signum(self) -> $T {
633+
match self {
634+
n if n > 0 => 1,
635+
0 => 0,
636+
_ => -1,
637+
}
638+
}
639+
640+
#[inline]
641+
fn is_positive(self) -> bool { self > 0 }
642+
643+
#[inline]
644+
fn is_negative(self) -> bool { self < 0 }
645+
}
646+
}
647+
}
648+
649+
signed_int_impl!(i8)
650+
signed_int_impl!(i16)
651+
signed_int_impl!(i32)
652+
signed_int_impl!(i64)
653+
signed_int_impl!(int)
654+
705655
/// A built-in unsigned integer.
706656
pub trait UnsignedInt: Int {
707657
/// Returns `true` iff `self == 2^k` for some `k`.
@@ -1257,7 +1207,7 @@ pub trait Float
12571207
+ NumCast
12581208
+ PartialOrd
12591209
+ PartialEq
1260-
+ Signed
1210+
+ Neg<Self>
12611211
+ Add<Self,Self>
12621212
+ Sub<Self,Self>
12631213
+ Mul<Self,Self>
@@ -1327,6 +1277,22 @@ pub trait Float
13271277
/// Return the fractional part of a number.
13281278
fn fract(self) -> Self;
13291279

1280+
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
1281+
/// number is `Float::nan()`.
1282+
fn abs(self) -> Self;
1283+
/// Returns a number that represents the sign of `self`.
1284+
///
1285+
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
1286+
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
1287+
/// - `Float::nan()` if the number is `Float::nan()`
1288+
fn signum(self) -> Self;
1289+
/// Returns `true` if `self` is positive, including `+0.0` and
1290+
/// `Float::infinity()`.
1291+
fn is_positive(self) -> bool;
1292+
/// Returns `true` if `self` is negative, including `-0.0` and
1293+
/// `Float::neg_infinity()`.
1294+
fn is_negative(self) -> bool;
1295+
13301296
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
13311297
/// error. This produces a more accurate result with better performance than
13321298
/// a separate multiplication operation followed by an add.
@@ -1494,14 +1460,6 @@ one_impl!(i64, 1i64)
14941460
one_impl!(f32, 1.0f32)
14951461
one_impl!(f64, 1.0f64)
14961462

1497-
#[deprecated = "Use `Signed::abs`"]
1498-
pub fn abs<T: Signed>(value: T) -> T {
1499-
value.abs()
1500-
}
1501-
#[deprecated = "Use `Signed::signum`"]
1502-
pub fn signum<T: Signed>(value: T) -> T {
1503-
value.signum()
1504-
}
15051463
#[deprecated = "Use `UnsignedInt::next_power_of_two`"]
15061464
pub fn next_power_of_two<T: UnsignedInt>(n: T) -> T {
15071465
n.next_power_of_two()

0 commit comments

Comments
 (0)