Skip to content

Commit b9551ca

Browse files
author
James Miller
committed
---
yaml --- r: 57164 b: refs/heads/try c: 286e571 h: refs/heads/master v: v3
1 parent 4d7da85 commit b9551ca

File tree

18 files changed

+196
-713
lines changed

18 files changed

+196
-713
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: c8ac057545f7b2edf1e488aa4562138a6ed7a096
5+
refs/heads/try: 286e571a634e9677fe897ff8fb46a7e33487b4c5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
105105
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
106106
pub use iter::{ExtendedMutableIter};
107107

108-
pub use num::{Num, Signed, Unsigned, Natural, NumCast};
108+
pub use num::{Num, NumCast};
109109
pub use ptr::Ptr;
110110
pub use to_str::ToStr;
111111
pub use clone::Clone;

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

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! Operations and constants for `f32`
1212
1313
use num::strconv;
14-
use num::Signed;
1514
use num;
1615
use option::Option;
1716
use from_str;
@@ -164,6 +163,38 @@ pub fn gt(x: f32, y: f32) -> bool { return x > y; }
164163
// FIXME (#1999): replace the predicates below with llvm intrinsics or
165164
// calls to the libmath macros in the rust runtime for performance.
166165

166+
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
167+
#[inline(always)]
168+
pub fn is_positive(x: f32) -> bool {
169+
x > 0.0f32 || (1.0f32/x) == infinity
170+
}
171+
172+
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
173+
#[inline(always)]
174+
pub fn is_negative(x: f32) -> bool {
175+
x < 0.0f32 || (1.0f32/x) == neg_infinity
176+
}
177+
178+
/**
179+
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
180+
*
181+
* This is the same as `f32::is_negative`.
182+
*/
183+
#[inline(always)]
184+
pub fn is_nonpositive(x: f32) -> bool {
185+
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
186+
}
187+
188+
/**
189+
* Returns true if `x` is a positive number, including +0.0f320 and +Infinity
190+
*
191+
* This is the same as `f32::is_positive`.)
192+
*/
193+
#[inline(always)]
194+
pub fn is_nonnegative(x: f32) -> bool {
195+
return x > 0.0f32 || (1.0f32/x) == infinity;
196+
}
197+
167198
/// Returns true if `x` is a zero number (positive or negative zero)
168199
#[inline(always)]
169200
pub fn is_zero(x: f32) -> bool {
@@ -228,6 +259,11 @@ pub mod consts {
228259
pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32;
229260
}
230261

262+
#[inline(always)]
263+
pub fn signbit(x: f32) -> int {
264+
if is_negative(x) { return 1; } else { return 0; }
265+
}
266+
231267
#[inline(always)]
232268
pub fn logarithm(n: f32, b: f32) -> f32 {
233269
return log2(n) / log2(b);
@@ -315,41 +351,15 @@ impl Neg<f32> for f32 {
315351
fn neg(&self) -> f32 { -*self }
316352
}
317353

318-
impl Signed for f32 {
319-
/// Computes the absolute value. Returns `NaN` if the number is `NaN`.
320-
#[inline(always)]
321-
fn abs(&self) -> f32 { abs(*self) }
322-
323-
/**
324-
* # Returns
325-
*
326-
* - `1.0` if the number is positive, `+0.0` or `infinity`
327-
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
328-
* - `NaN` if the number is `NaN`
329-
*/
330-
#[inline(always)]
331-
fn signum(&self) -> f32 {
332-
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
333-
}
334-
335-
/// Returns `true` if the number is positive, including `+0.0` and `infinity`
336-
#[inline(always)]
337-
fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == infinity }
338-
339-
/// Returns `true` if the number is negative, including `-0.0` and `neg_infinity`
340-
#[inline(always)]
341-
fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == neg_infinity }
342-
}
343-
344354
impl num::Round for f32 {
345355
#[inline(always)]
346356
fn round(&self, mode: num::RoundMode) -> f32 {
347357
match mode {
348358
num::RoundDown => floor(*self),
349359
num::RoundUp => ceil(*self),
350-
num::RoundToZero if self.is_negative() => ceil(*self),
360+
num::RoundToZero if is_negative(*self) => ceil(*self),
351361
num::RoundToZero => floor(*self),
352-
num::RoundFromZero if self.is_negative() => floor(*self),
362+
num::RoundFromZero if is_negative(*self) => floor(*self),
353363
num::RoundFromZero => ceil(*self)
354364
}
355365
}
@@ -360,7 +370,7 @@ impl num::Round for f32 {
360370
fn ceil(&self) -> f32 { ceil(*self) }
361371
#[inline(always)]
362372
fn fract(&self) -> f32 {
363-
if self.is_negative() {
373+
if is_negative(*self) {
364374
(*self) - ceil(*self)
365375
} else {
366376
(*self) - floor(*self)
@@ -585,50 +595,6 @@ impl num::FromStrRadix for f32 {
585595
}
586596
}
587597

588-
#[cfg(test)]
589-
mod tests {
590-
use f32::*;
591-
592-
#[test]
593-
pub fn test_signed() {
594-
assert_eq!(infinity.abs(), infinity);
595-
assert_eq!(1f32.abs(), 1f32);
596-
assert_eq!(0f32.abs(), 0f32);
597-
assert_eq!((-0f32).abs(), 0f32);
598-
assert_eq!((-1f32).abs(), 1f32);
599-
assert_eq!(neg_infinity.abs(), infinity);
600-
assert_eq!((1f32/neg_infinity).abs(), 0f32);
601-
assert!(is_NaN(NaN.abs()));
602-
603-
assert_eq!(infinity.signum(), 1f32);
604-
assert_eq!(1f32.signum(), 1f32);
605-
assert_eq!(0f32.signum(), 1f32);
606-
assert_eq!((-0f32).signum(), -1f32);
607-
assert_eq!((-1f32).signum(), -1f32);
608-
assert_eq!(neg_infinity.signum(), -1f32);
609-
assert_eq!((1f32/neg_infinity).signum(), -1f32);
610-
assert!(is_NaN(NaN.signum()));
611-
612-
assert!(infinity.is_positive());
613-
assert!(1f32.is_positive());
614-
assert!(0f32.is_positive());
615-
assert!(!(-0f32).is_positive());
616-
assert!(!(-1f32).is_positive());
617-
assert!(!neg_infinity.is_positive());
618-
assert!(!(1f32/neg_infinity).is_positive());
619-
assert!(!NaN.is_positive());
620-
621-
assert!(!infinity.is_negative());
622-
assert!(!1f32.is_negative());
623-
assert!(!0f32.is_negative());
624-
assert!((-0f32).is_negative());
625-
assert!((-1f32).is_negative());
626-
assert!(neg_infinity.is_negative());
627-
assert!((1f32/neg_infinity).is_negative());
628-
assert!(!NaN.is_negative());
629-
}
630-
}
631-
632598
//
633599
// Local Variables:
634600
// mode: rust

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

Lines changed: 38 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! Operations and constants for `f64`
1212
1313
use num::strconv;
14-
use num::Signed;
1514
use num;
1615
use option::Option;
1716
use to_str;
@@ -184,6 +183,36 @@ pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
184183
#[inline(always)]
185184
pub fn gt(x: f64, y: f64) -> bool { return x > y; }
186185

186+
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
187+
#[inline(always)]
188+
pub fn is_positive(x: f64) -> bool
189+
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
190+
191+
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
192+
#[inline(always)]
193+
pub fn is_negative(x: f64) -> bool
194+
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
195+
196+
/**
197+
* Returns true if `x` is a negative number, including -0.0f640 and -Infinity
198+
*
199+
* This is the same as `f64::is_negative`.
200+
*/
201+
#[inline(always)]
202+
pub fn is_nonpositive(x: f64) -> bool {
203+
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
204+
}
205+
206+
/**
207+
* Returns true if `x` is a positive number, including +0.0f640 and +Infinity
208+
*
209+
* This is the same as `f64::positive`.
210+
*/
211+
#[inline(always)]
212+
pub fn is_nonnegative(x: f64) -> bool {
213+
return x > 0.0f64 || (1.0f64/x) == infinity;
214+
}
215+
187216
/// Returns true if `x` is a zero number (positive or negative zero)
188217
#[inline(always)]
189218
pub fn is_zero(x: f64) -> bool {
@@ -249,6 +278,11 @@ pub mod consts {
249278
pub static ln_10: f64 = 2.30258509299404568401799145468436421_f64;
250279
}
251280

281+
#[inline(always)]
282+
pub fn signbit(x: f64) -> int {
283+
if is_negative(x) { return 1; } else { return 0; }
284+
}
285+
252286
#[inline(always)]
253287
pub fn logarithm(n: f64, b: f64) -> f64 {
254288
return log2(n) / log2(b);
@@ -323,41 +357,15 @@ impl Neg<f64> for f64 {
323357
fn neg(&self) -> f64 { -*self }
324358
}
325359

326-
impl Signed for f64 {
327-
/// Computes the absolute value. Returns `NaN` if the number is `NaN`.
328-
#[inline(always)]
329-
fn abs(&self) -> f64 { abs(*self) }
330-
331-
/**
332-
* # Returns
333-
*
334-
* - `1.0` if the number is positive, `+0.0` or `infinity`
335-
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
336-
* - `NaN` if the number is `NaN`
337-
*/
338-
#[inline(always)]
339-
fn signum(&self) -> f64 {
340-
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
341-
}
342-
343-
/// Returns `true` if the number is positive, including `+0.0` and `infinity`
344-
#[inline(always)]
345-
fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == infinity }
346-
347-
/// Returns `true` if the number is negative, including `-0.0` and `neg_infinity`
348-
#[inline(always)]
349-
fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == neg_infinity }
350-
}
351-
352360
impl num::Round for f64 {
353361
#[inline(always)]
354362
fn round(&self, mode: num::RoundMode) -> f64 {
355363
match mode {
356364
num::RoundDown => floor(*self),
357365
num::RoundUp => ceil(*self),
358-
num::RoundToZero if self.is_negative() => ceil(*self),
366+
num::RoundToZero if is_negative(*self) => ceil(*self),
359367
num::RoundToZero => floor(*self),
360-
num::RoundFromZero if self.is_negative() => floor(*self),
368+
num::RoundFromZero if is_negative(*self) => floor(*self),
361369
num::RoundFromZero => ceil(*self)
362370
}
363371
}
@@ -368,7 +376,7 @@ impl num::Round for f64 {
368376
fn ceil(&self) -> f64 { ceil(*self) }
369377
#[inline(always)]
370378
fn fract(&self) -> f64 {
371-
if self.is_negative() {
379+
if is_negative(*self) {
372380
(*self) - ceil(*self)
373381
} else {
374382
(*self) - floor(*self)
@@ -593,50 +601,6 @@ impl num::FromStrRadix for f64 {
593601
}
594602
}
595603

596-
#[cfg(test)]
597-
mod tests {
598-
use f64::*;
599-
600-
#[test]
601-
pub fn test_signed() {
602-
assert_eq!(infinity.abs(), infinity);
603-
assert_eq!(1f64.abs(), 1f64);
604-
assert_eq!(0f64.abs(), 0f64);
605-
assert_eq!((-0f64).abs(), 0f64);
606-
assert_eq!((-1f64).abs(), 1f64);
607-
assert_eq!(neg_infinity.abs(), infinity);
608-
assert_eq!((1f64/neg_infinity).abs(), 0f64);
609-
assert!(is_NaN(NaN.abs()));
610-
611-
assert_eq!(infinity.signum(), 1f64);
612-
assert_eq!(1f64.signum(), 1f64);
613-
assert_eq!(0f64.signum(), 1f64);
614-
assert_eq!((-0f64).signum(), -1f64);
615-
assert_eq!((-1f64).signum(), -1f64);
616-
assert_eq!(neg_infinity.signum(), -1f64);
617-
assert_eq!((1f64/neg_infinity).signum(), -1f64);
618-
assert!(is_NaN(NaN.signum()));
619-
620-
assert!(infinity.is_positive());
621-
assert!(1f64.is_positive());
622-
assert!(0f64.is_positive());
623-
assert!(!(-0f64).is_positive());
624-
assert!(!(-1f64).is_positive());
625-
assert!(!neg_infinity.is_positive());
626-
assert!(!(1f64/neg_infinity).is_positive());
627-
assert!(!NaN.is_positive());
628-
629-
assert!(!infinity.is_negative());
630-
assert!(!1f64.is_negative());
631-
assert!(!0f64.is_negative());
632-
assert!((-0f64).is_negative());
633-
assert!((-1f64).is_negative());
634-
assert!(neg_infinity.is_negative());
635-
assert!((1f64/neg_infinity).is_negative());
636-
assert!(!NaN.is_negative());
637-
}
638-
}
639-
640604
//
641605
// Local Variables:
642606
// mode: rust

0 commit comments

Comments
 (0)