Skip to content

Commit ae049b2

Browse files
committed
---
yaml --- r: 159581 b: refs/heads/auto c: 878bebf h: refs/heads/master i: 159579: 64ced21 v: v3
1 parent f6c2ba0 commit ae049b2

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
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: 26196715e8e8fb3a578cc89a54c13773dc1a3772
13+
refs/heads/auto: 878bebfb63db6ea81f1fb738f4eeaa3afb8e55e4
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

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

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub trait Signed: Neg<Self> {
6464
fn is_negative(self) -> bool;
6565
}
6666

67-
macro_rules! signed_impl(
68-
($($T:ty)*) => ($(
67+
macro_rules! signed_int_impl {
68+
($T:ty) => {
6969
impl Signed for $T {
7070
#[inline]
7171
fn abs(self) -> $T {
@@ -75,9 +75,9 @@ macro_rules! signed_impl(
7575
#[inline]
7676
fn signum(self) -> $T {
7777
match self {
78-
n if n > 0 => 1,
79-
0 => 0,
80-
_ => -1,
78+
n if n > 0 => 1,
79+
0 => 0,
80+
_ => -1,
8181
}
8282
}
8383

@@ -87,13 +87,17 @@ macro_rules! signed_impl(
8787
#[inline]
8888
fn is_negative(self) -> bool { self < 0 }
8989
}
90-
)*)
91-
)
90+
}
91+
}
9292

93-
signed_impl!(int i8 i16 i32 i64)
93+
signed_int_impl!(i8)
94+
signed_int_impl!(i16)
95+
signed_int_impl!(i32)
96+
signed_int_impl!(i64)
97+
signed_int_impl!(int)
9498

95-
macro_rules! signed_float_impl(
96-
($T:ty, $nan:expr, $inf:expr, $neg_inf:expr, $fabs:path, $fcopysign:path, $fdim:ident) => {
99+
macro_rules! signed_float_impl {
100+
($T:ty, $fabs:path, $fcopysign:path) => {
97101
impl Signed for $T {
98102
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
99103
#[inline]
@@ -103,46 +107,42 @@ macro_rules! signed_float_impl(
103107

104108
/// # Returns
105109
///
106-
/// - `1.0` if the number is positive, `+0.0` or `INFINITY`
107-
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
108-
/// - `NAN` if the number is NaN
110+
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
111+
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
112+
/// - `Float::nan()` if the number is `Float::nan()`
109113
#[inline]
110114
fn signum(self) -> $T {
111-
if self != self { $nan } else {
115+
if self.is_nan() {
116+
Float::nan()
117+
} else {
112118
unsafe { $fcopysign(1.0, self) }
113119
}
114120
}
115121

116-
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
122+
/// Returns `true` if the number is positive, including `+0.0` and
123+
/// `Float::infinity()`.
117124
#[inline]
118-
fn is_positive(self) -> bool { self > 0.0 || (1.0 / self) == $inf }
125+
fn is_positive(self) -> bool {
126+
self > 0.0 || (1.0 / self) == Float::infinity()
127+
}
119128

120-
/// Returns `true` if the number is negative, including `-0.0` and `NEG_INFINITY`
129+
/// Returns `true` if the number is negative, including `-0.0` and
130+
/// `Float::neg_infinity()`.
121131
#[inline]
122-
fn is_negative(self) -> bool { self < 0.0 || (1.0 / self) == $neg_inf }
132+
fn is_negative(self) -> bool {
133+
self < 0.0 || (1.0 / self) == Float::neg_infinity()
134+
}
123135
}
124-
}
125-
)
136+
};
137+
}
126138

127-
signed_float_impl!(f32, f32::NAN, f32::INFINITY, f32::NEG_INFINITY,
128-
intrinsics::fabsf32, intrinsics::copysignf32, fdimf)
129-
signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY,
130-
intrinsics::fabsf64, intrinsics::copysignf64, fdim)
139+
signed_float_impl!(f32,
140+
intrinsics::fabsf32,
141+
intrinsics::copysignf32)
131142

132-
/// Returns the sign of the number.
133-
///
134-
/// For `f32` and `f64`:
135-
///
136-
/// * `1.0` if the number is positive, `+0.0` or `INFINITY`
137-
/// * `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
138-
/// * `NaN` if the number is `NaN`
139-
///
140-
/// For signed integers:
141-
///
142-
/// * `0` if the number is zero
143-
/// * `1` if the number is positive
144-
/// * `-1` if the number is negative
145-
#[inline(always)] pub fn signum<T: Signed>(value: T) -> T { value.signum() }
143+
signed_float_impl!(f64,
144+
intrinsics::fabsf64,
145+
intrinsics::copysignf64)
146146

147147
/// Raises a value to the power of exp, using exponentiation by squaring.
148148
///
@@ -1481,6 +1481,10 @@ one_impl!(f64, 1.0f64)
14811481
pub fn abs<T: Signed>(value: T) -> T {
14821482
value.abs()
14831483
}
1484+
#[deprecated = "Use `Signed::signum`"]
1485+
pub fn signum<T: Signed>(value: T) -> T {
1486+
value.signum()
1487+
}
14841488
#[deprecated = "Use `UnsignedInt::next_power_of_two`"]
14851489
pub fn next_power_of_two<T: UnsignedInt>(n: T) -> T {
14861490
n.next_power_of_two()

0 commit comments

Comments
 (0)