From 593bdd9be3959f166c303e3da0678cc9598bffc4 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 24 Apr 2013 17:25:41 +1000 Subject: Fix incorrect replacement of `modulo` with `rem` --- src/libstd/base64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index cbdd2b19d27..e90f0fb3c81 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -118,7 +118,7 @@ pub trait FromBase64 { impl FromBase64 for ~[u8] { /** * Convert base64 `u8` vector into u8 byte values. - * Every 4 encoded characters is converted into 3 octets, rem padding. + * Every 4 encoded characters is converted into 3 octets, modulo padding. * * *Example*: * -- cgit 1.4.1-3-g733a5 From d4868ee74085c2dc2943ef9407ced2d06e43abf6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 24 Apr 2013 22:26:14 +1000 Subject: Use #[cfg(not(stage0))] to exclude items from stage0 As requested on the mailing list: https://mail.mozilla.org/pipermail/rust-dev/2013-April/003713.html --- src/libcore/core.rc | 4 +--- src/libcore/num/f32.rs | 10 ++-------- src/libcore/num/f64.rs | 8 ++------ src/libcore/num/float.rs | 8 ++------ src/libcore/num/int-template.rs | 10 ++-------- src/libcore/num/num.rs | 4 +--- src/libcore/num/uint-template.rs | 10 ++-------- src/libcore/ops.rs | 8 ++------ src/libcore/prelude.rs | 4 +--- src/libstd/std.rc | 16 ++++------------ 10 files changed, 19 insertions(+), 63 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 61fbf98a7c6..7890d611e85 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -77,9 +77,7 @@ pub use kinds::{Const, Copy, Owned, Durable}; pub use ops::{Drop}; #[cfg(stage0)] pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not}; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not}; pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{Shl, Shr, Index}; diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index e72356aa3cb..9e4140adcd1 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -278,10 +278,7 @@ impl Div for f32 { #[inline(always)] fn div(&self, other: &f32) -> f32 { *self / *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Quot for f32 { #[inline(always)] fn quot(&self, other: &f32) -> f32 { *self / *other } @@ -292,10 +289,7 @@ impl Modulo for f32 { #[inline(always)] fn modulo(&self, other: &f32) -> f32 { *self % *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Rem for f32 { #[inline(always)] fn rem(&self, other: &f32) -> f32 { *self % *other } diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index c9867f5e6d4..12f86337e85 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -292,9 +292,7 @@ impl Mul for f64 { impl Div for f64 { fn div(&self, other: &f64) -> f64 { *self / *other } } -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Quot for f64 { #[inline(always)] fn quot(&self, other: &f64) -> f64 { *self / *other } @@ -303,9 +301,7 @@ impl Quot for f64 { impl Modulo for f64 { fn modulo(&self, other: &f64) -> f64 { *self % *other } } -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Rem for f64 { #[inline(always)] fn rem(&self, other: &f64) -> f64 { *self % *other } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index e2f3a4cbcdb..88321e6b8bf 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -459,9 +459,7 @@ impl Div for float { #[inline(always)] fn div(&self, other: &float) -> float { *self / *other } } -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Quot for float { #[inline(always)] fn quot(&self, other: &float) -> float { *self / *other } @@ -471,9 +469,7 @@ impl Modulo for float { #[inline(always)] fn modulo(&self, other: &float) -> float { *self % *other } } -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Rem for float { #[inline(always)] fn rem(&self, other: &float) -> float { *self % *other } diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 6598efa759e..cb29b9e4486 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -185,10 +185,7 @@ impl Div for T { #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Quot for T { /** * Returns the integer quotient, truncated towards 0. As this behaviour reflects @@ -217,10 +214,7 @@ impl Modulo for T { #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Rem for T { /** * Returns the integer remainder after division, satisfying: diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 62ed80114d3..8304179c346 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -16,9 +16,7 @@ use ops::{Add, Sub, Mul, Neg}; use Quot = ops::Div; #[cfg(stage0)] use Rem = ops::Modulo; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] use ops::{Add, Sub, Mul, Quot, Rem, Neg}; use option::Option; use kinds::Copy; diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index fc0fe2d3a4d..2ee64d4e4ea 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -151,10 +151,7 @@ impl Div for T { #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Quot for T { #[inline(always)] fn quot(&self, other: &T) -> T { *self / *other } @@ -165,10 +162,7 @@ impl Modulo for T { #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } - -#[cfg(stage1,notest)] -#[cfg(stage2,notest)] -#[cfg(stage3,notest)] +#[cfg(not(stage0),notest)] impl Rem for T { #[inline(always)] fn rem(&self, other: &T) -> T { *self % *other } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 465a9330f74..1aa7aada05c 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -36,9 +36,7 @@ pub trait Div { fn div(&self, rhs: &RHS) -> Result; } #[lang="quot"] -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] pub trait Quot { fn quot(&self, rhs: &RHS) -> Result; } @@ -49,9 +47,7 @@ pub trait Modulo { fn modulo(&self, rhs: &RHS) -> Result; } #[lang="rem"] -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] pub trait Rem { fn rem(&self, rhs: &RHS) -> Result; } diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 03e6065a85c..0af0cdf08c9 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -16,9 +16,7 @@ pub use either::{Either, Left, Right}; pub use kinds::{Const, Copy, Owned, Durable}; #[cfg(stage0)] pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not}; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not}; pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{Drop}; diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 7bedef0f841..07c679409cf 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -76,9 +76,7 @@ pub mod rope; pub mod smallintmap; pub mod sort; pub mod dlist; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] pub mod treemap; // And ... other stuff @@ -98,19 +96,13 @@ pub mod cmp; pub mod base64; pub mod rl; pub mod workcache; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] #[path="num/bigint.rs"] pub mod bigint; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] #[path="num/rational.rs"] pub mod rational; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] +#[cfg(not(stage0))] #[path="num/complex.rs"] pub mod complex; pub mod stats; -- cgit 1.4.1-3-g733a5 From 225ac216157cf530332cef1c926875e2023e48e6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 25 Apr 2013 11:53:51 +1000 Subject: Update impl of Round for Ratio --- src/libstd/num/rational.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/rational.rs b/src/libstd/num/rational.rs index 36652380bff..8af1d99fa47 100644 --- a/src/libstd/num/rational.rs +++ b/src/libstd/num/rational.rs @@ -204,20 +204,6 @@ impl /* Utils */ impl Round for Ratio { - fn round(&self, mode: num::RoundMode) -> Ratio { - match mode { - num::RoundUp => { self.ceil() } - num::RoundDown => { self.floor()} - num::RoundToZero => { Ratio::from_integer(self.numer / self.denom) } - num::RoundFromZero => { - if *self < Zero::zero() { - Ratio::from_integer((self.numer - self.denom + One::one()) / self.denom) - } else { - Ratio::from_integer((self.numer + self.denom - One::one()) / self.denom) - } - } - } - } fn floor(&self) -> Ratio { if *self < Zero::zero() { @@ -226,6 +212,7 @@ impl Ratio::from_integer(self.numer / self.denom) } } + fn ceil(&self) -> Ratio { if *self < Zero::zero() { Ratio::from_integer(self.numer / self.denom) @@ -233,6 +220,21 @@ impl Ratio::from_integer((self.numer + self.denom - One::one()) / self.denom) } } + + #[inline(always)] + fn round(&self) -> Ratio { + if *self < Zero::zero() { + Ratio::from_integer((self.numer - self.denom + One::one()) / self.denom) + } else { + Ratio::from_integer((self.numer + self.denom - One::one()) / self.denom) + } + } + + #[inline(always)] + fn trunc(&self) -> Ratio { + Ratio::from_integer(self.numer / self.denom) + } + fn fract(&self) -> Ratio { Ratio::new_raw(self.numer % self.denom, self.denom) } @@ -421,18 +423,18 @@ mod test { fn test_round() { assert_eq!(_1_2.ceil(), _1); assert_eq!(_1_2.floor(), _0); - assert_eq!(_1_2.round(num::RoundToZero), _0); - assert_eq!(_1_2.round(num::RoundFromZero), _1); + assert_eq!(_1_2.round(), _1); + assert_eq!(_1_2.trunc(), _0); assert_eq!(_neg1_2.ceil(), _0); assert_eq!(_neg1_2.floor(), -_1); - assert_eq!(_neg1_2.round(num::RoundToZero), _0); - assert_eq!(_neg1_2.round(num::RoundFromZero), -_1); + assert_eq!(_neg1_2.round(), -_1); + assert_eq!(_neg1_2.trunc(), _0); assert_eq!(_1.ceil(), _1); assert_eq!(_1.floor(), _1); - assert_eq!(_1.round(num::RoundToZero), _1); - assert_eq!(_1.round(num::RoundFromZero), _1); + assert_eq!(_1.round(), _1); + assert_eq!(_1.trunc(), _1); } #[test] -- cgit 1.4.1-3-g733a5