diff --git a/doc/rust.md b/doc/rust.md index e9c88fc34121c..b1eb5521b398f 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1467,10 +1467,10 @@ A complete list of the built-in language items follows: : Elements can be subtracted. `mul` : Elements can be multiplied. -`div` - : Elements can be divided. -`mod` - : Elements have a modulo operation. +`quot` + : Elements have a quotient operation. +`rem` + : Elements have a remainder operation. `neg` : Elements can be negated arithmetically. `not` @@ -1856,11 +1856,11 @@ The default meaning of the operators on standard types is given here. : Multiplication. Calls the `mul` method on the `core::ops::Mul` trait. `/` - : Division. - Calls the `div` method on the `core::ops::Div` trait. + : Quotient. + Calls the `quot` method on the `core::ops::Quot` trait. `%` - : Modulo (a.k.a. "remainder"). - Calls the `modulo` method on the `core::ops::Modulo` trait. + : Remainder. + Calls the `rem` method on the `core::ops::Rem` trait. #### Bitwise operators diff --git a/doc/tutorial.md b/doc/tutorial.md index 56629b93b1a49..c10bc8a294c5d 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -362,7 +362,7 @@ The nil type, written `()`, has a single value, also written `()`. ## Operators Rust's set of operators contains very few surprises. Arithmetic is done with -`*`, `/`, `%`, `+`, and `-` (multiply, divide, take remainder, add, and subtract). `-` is +`*`, `/`, `%`, `+`, and `-` (multiply, quotient, remainder, add, and subtract). `-` is also a unary prefix operator that negates numbers. As in C, the bitwise operators `>>`, `<<`, `&`, `|`, and `^` are also supported. diff --git a/src/etc/kate/rust.xml b/src/etc/kate/rust.xml index 59f8c164588b3..6a751bd1c8588 100644 --- a/src/etc/kate/rust.xml +++ b/src/etc/kate/rust.xml @@ -57,8 +57,8 @@ Add Sub Mul - Div - Modulo + Quot + Rem Neg BitAnd BitOr diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 3e6c11c6238b1..eab3627ae16d1 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -46,7 +46,7 @@ syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t syn keyword rustTrait Const Copy Send Owned " inherent traits syn keyword rustTrait Eq Ord Num Ptr -syn keyword rustTrait Drop Add Sub Mul Div Modulo Neg BitAnd BitOr +syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr syn keyword rustTrait BitXor Shl Shr Index syn keyword rustSelf self diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 81190ea8fc62e..fd8813d0c4a45 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -75,7 +75,12 @@ they contained the following prologue: 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)] +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 6233f8c2a61b5..2e7dc98e3c56c 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -16,8 +16,13 @@ use option::Option; use from_str; use to_str; -#[cfg(notest)] use cmp; -#[cfg(notest)] use ops; +#[cfg(notest)] use cmp::{Eq, Ord}; +#[cfg(stage0,notest)] +use ops::{Add, Sub, Mul, Div, Modulo, Neg}; +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +use ops::{Add, Sub, Mul, Quot, Rem, Neg}; pub use cmath::c_float_targ_consts::*; @@ -131,7 +136,7 @@ pub fn sub(x: f32, y: f32) -> f32 { return x - y; } pub fn mul(x: f32, y: f32) -> f32 { return x * y; } #[inline(always)] -pub fn div(x: f32, y: f32) -> f32 { return x / y; } +pub fn quot(x: f32, y: f32) -> f32 { return x / y; } #[inline(always)] pub fn rem(x: f32, y: f32) -> f32 { return x % y; } @@ -265,7 +270,7 @@ pub fn logarithm(n: f32, b: f32) -> f32 { } #[cfg(notest)] -impl cmp::Eq for f32 { +impl Eq for f32 { #[inline(always)] fn eq(&self, other: &f32) -> bool { (*self) == (*other) } #[inline(always)] @@ -273,7 +278,7 @@ impl cmp::Eq for f32 { } #[cfg(notest)] -impl cmp::Ord for f32 { +impl Ord for f32 { #[inline(always)] fn lt(&self, other: &f32) -> bool { (*self) < (*other) } #[inline(always)] @@ -295,33 +300,41 @@ impl num::One for f32 { } #[cfg(notest)] -impl ops::Add for f32 { - #[inline(always)] +impl Add for f32 { fn add(&self, other: &f32) -> f32 { *self + *other } } #[cfg(notest)] -impl ops::Sub for f32 { - #[inline(always)] +impl Sub for f32 { fn sub(&self, other: &f32) -> f32 { *self - *other } } #[cfg(notest)] -impl ops::Mul for f32 { - #[inline(always)] +impl Mul for f32 { fn mul(&self, other: &f32) -> f32 { *self * *other } } -#[cfg(notest)] -impl ops::Div for f32 { - #[inline(always)] +#[cfg(stage0,notest)] +impl Div for f32 { fn div(&self, other: &f32) -> f32 { *self / *other } } -#[cfg(notest)] -impl ops::Modulo for f32 { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Quot for f32 { #[inline(always)] + fn quot(&self, other: &f32) -> f32 { *self / *other } +} +#[cfg(stage0,notest)] +impl Modulo for f32 { fn modulo(&self, other: &f32) -> f32 { *self % *other } } -#[cfg(notest)] -impl ops::Neg for f32 { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Rem for f32 { #[inline(always)] + fn rem(&self, other: &f32) -> f32 { *self % *other } +} +#[cfg(notest)] +impl Neg for f32 { fn neg(&self) -> f32 { -*self } } diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 7f32893f5bff7..4762c395a2561 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -16,8 +16,13 @@ use option::Option; use to_str; use from_str; -#[cfg(notest)] use cmp; -#[cfg(notest)] use ops; +#[cfg(notest)] use cmp::{Eq, Ord}; +#[cfg(stage0,notest)] +use ops::{Add, Sub, Mul, Div, Modulo, Neg}; +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +use ops::{Add, Sub, Mul, Quot, Rem, Neg}; pub use cmath::c_double_targ_consts::*; pub use cmp::{min, max}; @@ -155,7 +160,7 @@ pub fn sub(x: f64, y: f64) -> f64 { return x - y; } pub fn mul(x: f64, y: f64) -> f64 { return x * y; } #[inline(always)] -pub fn div(x: f64, y: f64) -> f64 { return x / y; } +pub fn quot(x: f64, y: f64) -> f64 { return x / y; } #[inline(always)] pub fn rem(x: f64, y: f64) -> f64 { return x % y; } @@ -284,7 +289,7 @@ pub fn logarithm(n: f64, b: f64) -> f64 { } #[cfg(notest)] -impl cmp::Eq for f64 { +impl Eq for f64 { #[inline(always)] fn eq(&self, other: &f64) -> bool { (*self) == (*other) } #[inline(always)] @@ -292,7 +297,7 @@ impl cmp::Eq for f64 { } #[cfg(notest)] -impl cmp::Ord for f64 { +impl Ord for f64 { #[inline(always)] fn lt(&self, other: &f64) -> bool { (*self) < (*other) } #[inline(always)] @@ -314,33 +319,41 @@ impl num::One for f64 { } #[cfg(notest)] -impl ops::Add for f64 { - #[inline(always)] +impl Add for f64 { fn add(&self, other: &f64) -> f64 { *self + *other } } #[cfg(notest)] -impl ops::Sub for f64 { - #[inline(always)] +impl Sub for f64 { fn sub(&self, other: &f64) -> f64 { *self - *other } } #[cfg(notest)] -impl ops::Mul for f64 { - #[inline(always)] +impl Mul for f64 { fn mul(&self, other: &f64) -> f64 { *self * *other } } -#[cfg(notest)] -impl ops::Div for f64 { - #[inline(always)] +#[cfg(stage0,notest)] +impl Div for f64 { fn div(&self, other: &f64) -> f64 { *self / *other } } -#[cfg(notest)] -impl ops::Modulo for f64 { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Quot for f64 { #[inline(always)] + fn quot(&self, other: &f64) -> f64 { *self / *other } +} +#[cfg(stage0,notest)] +impl Modulo for f64 { fn modulo(&self, other: &f64) -> f64 { *self % *other } } -#[cfg(notest)] -impl ops::Neg for f64 { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Rem for f64 { #[inline(always)] + fn rem(&self, other: &f64) -> f64 { *self % *other } +} +#[cfg(notest)] +impl Neg for f64 { fn neg(&self) -> f64 { -*self } } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index c9cda20640d56..9cf14cf0f494b 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -28,9 +28,14 @@ use to_str; use from_str; #[cfg(notest)] use cmp::{Eq, Ord}; -#[cfg(notest)] use ops; - -pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; +#[cfg(stage0,notest)] +use ops::{Add, Sub, Mul, Div, Modulo, Neg}; +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +use ops::{Add, Sub, Mul, Quot, Rem, Neg}; + +pub use f64::{add, sub, mul, quot, rem, lt, le, eq, ne, ge, gt}; pub use f64::logarithm; pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor}; pub use f64::{erf, erfc, exp, expm1, exp2, abs_sub}; @@ -449,33 +454,41 @@ impl num::Round for float { } #[cfg(notest)] -impl ops::Add for float { - #[inline(always)] +impl Add for float { fn add(&self, other: &float) -> float { *self + *other } } #[cfg(notest)] -impl ops::Sub for float { - #[inline(always)] +impl Sub for float { fn sub(&self, other: &float) -> float { *self - *other } } #[cfg(notest)] -impl ops::Mul for float { - #[inline(always)] +impl Mul for float { fn mul(&self, other: &float) -> float { *self * *other } } -#[cfg(notest)] -impl ops::Div for float { - #[inline(always)] +#[cfg(stage0,notest)] +impl Div for float { fn div(&self, other: &float) -> float { *self / *other } } -#[cfg(notest)] -impl ops::Modulo for float { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Quot for float { #[inline(always)] + fn quot(&self, other: &float) -> float { *self / *other } +} +#[cfg(stage0,notest)] +impl Modulo for float { fn modulo(&self, other: &float) -> float { *self % *other } } -#[cfg(notest)] -impl ops::Neg for float { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Rem for float { #[inline(always)] + fn rem(&self, other: &float) -> float { *self % *other } +} +#[cfg(notest)] +impl Neg for float { fn neg(&self) -> float { -*self } } diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index e170d85cc716e..8f448994c9811 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -17,8 +17,6 @@ use num::strconv; use num; use prelude::*; -#[cfg(notest)] use cmp::{Eq, Ord}; - pub use cmp::{min, max}; pub static bits : uint = inst::bits; @@ -34,7 +32,7 @@ pub fn sub(x: T, y: T) -> T { x - y } #[inline(always)] pub fn mul(x: T, y: T) -> T { x * y } #[inline(always)] -pub fn div(x: T, y: T) -> T { x / y } +pub fn quot(x: T, y: T) -> T { x / y } /** * Returns the remainder of y / x. @@ -176,63 +174,71 @@ impl num::One for T { } #[cfg(notest)] -impl ops::Add for T { - #[inline(always)] +impl Add for T { fn add(&self, other: &T) -> T { *self + *other } } #[cfg(notest)] -impl ops::Sub for T { - #[inline(always)] +impl Sub for T { fn sub(&self, other: &T) -> T { *self - *other } } #[cfg(notest)] -impl ops::Mul for T { - #[inline(always)] +impl Mul for T { fn mul(&self, other: &T) -> T { *self * *other } } -#[cfg(notest)] -impl ops::Div for T { - #[inline(always)] +#[cfg(stage0,notest)] +impl Div for T { fn div(&self, other: &T) -> T { *self / *other } } -#[cfg(notest)] -impl ops::Modulo for T { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Quot for T { #[inline(always)] + fn quot(&self, other: &T) -> T { *self / *other } +} +#[cfg(stage0,notest)] +impl Modulo for T { fn modulo(&self, other: &T) -> T { *self % *other } } -#[cfg(notest)] -impl ops::Neg for T { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Rem for T { #[inline(always)] + fn rem(&self, other: &T) -> T { *self % *other } +} +#[cfg(notest)] +impl Neg for T { fn neg(&self) -> T { -*self } } #[cfg(notest)] -impl ops::BitOr for T { +impl BitOr for T { #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } #[cfg(notest)] -impl ops::BitAnd for T { +impl BitAnd for T { #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } #[cfg(notest)] -impl ops::BitXor for T { +impl BitXor for T { #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } #[cfg(notest)] -impl ops::Shl for T { +impl Shl for T { #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } #[cfg(notest)] -impl ops::Shr for T { +impl Shr for T { #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } #[cfg(notest)] -impl ops::Not for T { +impl Not for T { #[inline(always)] fn not(&self) -> T { !*self } } diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 5834214475219..a0ff510cde7da 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -10,7 +10,16 @@ //! An interface for numeric types use cmp::{Eq, Ord}; -use ops::{Neg, Add, Sub, Mul, Div, Modulo}; +#[cfg(stage0)] +use ops::{Add, Sub, Mul, Neg}; +#[cfg(stage0)] +use Quot = ops::Div; +#[cfg(stage0)] +use Rem = ops::Modulo; +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +use ops::{Add, Sub, Mul, Quot, Rem, Neg}; use option::Option; use kinds::Copy; @@ -21,8 +30,8 @@ pub trait Num: Eq + Zero + One + Add + Sub + Mul - + Div - + Modulo {} + + Quot + + Rem {} impl Num for u8 {} impl Num for u16 {} @@ -174,7 +183,7 @@ pub trait FromStrRadix { * - If code written to use this function doesn't care about it, it's * probably assuming that `x^0` always equals `1`. */ -pub fn pow_with_uint+Mul>( +pub fn pow_with_uint+Mul>( radix: uint, pow: uint) -> T { let _0: T = Zero::zero(); let _1: T = One::one(); @@ -194,7 +203,7 @@ pub fn pow_with_uint+Mul>( total } -#[cfg(test)] +#[cfg(stage0,test)] fn test_num(ten: T, two: T) { assert_eq!(ten.add(&two), cast(12)); assert_eq!(ten.sub(&two), cast(8)); @@ -208,6 +217,22 @@ fn test_num(ten: T, two: T) { assert_eq!(ten.div(&two), ten / two); assert_eq!(ten.modulo(&two), ten % two); } +#[cfg(stage1,test)] +#[cfg(stage2,test)] +#[cfg(stage3,test)] +fn test_num(ten: T, two: T) { + assert_eq!(ten.add(&two), cast(12)); + assert_eq!(ten.sub(&two), cast(8)); + assert_eq!(ten.mul(&two), cast(20)); + assert_eq!(ten.quot(&two), cast(5)); + assert_eq!(ten.rem(&two), cast(0)); + + assert_eq!(ten.add(&two), ten + two); + assert_eq!(ten.sub(&two), ten - two); + assert_eq!(ten.mul(&two), ten * two); + assert_eq!(ten.quot(&two), ten / two); + assert_eq!(ten.rem(&two), ten % two); +} #[test] fn test_u8_num() { test_num(10u8, 2u8) } #[test] fn test_u16_num() { test_num(10u16, 2u16) } diff --git a/src/libcore/num/strconv.rs b/src/libcore/num/strconv.rs index de699a3756b6e..4a45a1d97023e 100644 --- a/src/libcore/num/strconv.rs +++ b/src/libcore/num/strconv.rs @@ -9,7 +9,16 @@ // except according to those terms. use core::cmp::{Ord, Eq}; -use ops::{Add, Div, Modulo, Mul, Neg, Sub}; +#[cfg(stage0)] +use ops::{Add, Sub, Mul, Neg}; +#[cfg(stage0)] +use Quot = ops::Div; +#[cfg(stage0)] +use Rem = ops::Modulo; +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +use ops::{Add, Sub, Mul, Quot, Rem, Neg}; use option::{None, Option, Some}; use char; use str; @@ -58,7 +67,7 @@ fn is_neg_inf(num: &T) -> bool { } #[inline(always)] -fn is_neg_zero>(num: &T) -> bool { +fn is_neg_zero>(num: &T) -> bool { let _0: T = Zero::zero(); let _1: T = One::one(); @@ -171,7 +180,7 @@ static nan_buf: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8]; * - Fails if `radix` < 2 or `radix` > 36. */ pub fn to_str_bytes_common+Neg+Modulo+Mul>( + Quot+Neg+Rem+Mul>( num: &T, radix: uint, negative_zero: bool, sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) { if (radix as int) < 2 { @@ -379,7 +388,7 @@ pub fn to_str_bytes_common+Neg+Modulo+Mul>( + Quot+Neg+Rem+Mul>( num: &T, radix: uint, negative_zero: bool, sign: SignFormat, digits: SignificantDigits) -> (~str, bool) { let (bytes, special) = to_str_bytes_common(num, radix, @@ -432,7 +441,7 @@ priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u; * - Fails if `radix` > 18 and `special == true` due to conflict * between digit and lowest first character in `inf` and `NaN`, the `'i'`. */ -pub fn from_str_bytes_common+ +pub fn from_str_bytes_common+ Mul+Sub+Neg+Add+ NumStrConv>( buf: &[u8], radix: uint, negative: bool, fractional: bool, @@ -629,7 +638,7 @@ pub fn from_str_bytes_common+ * `from_str_bytes_common()`, for details see there. */ #[inline(always)] -pub fn from_str_common+Mul+ +pub fn from_str_common+Mul+ Sub+Neg+Add+NumStrConv>( buf: &str, radix: uint, negative: bool, fractional: bool, special: bool, exponent: ExponentFormat, empty_zero: bool, diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 0fb6ea614d861..6f3f402f92d69 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -19,8 +19,6 @@ use num; use option::Option; use prelude::*; -#[cfg(notest)] use cmp::{Eq, Ord}; - pub use cmp::{min, max}; pub static bits : uint = inst::bits; @@ -36,7 +34,7 @@ pub fn sub(x: T, y: T) -> T { x - y } #[inline(always)] pub fn mul(x: T, y: T) -> T { x * y } #[inline(always)] -pub fn div(x: T, y: T) -> T { x / y } +pub fn quot(x: T, y: T) -> T { x / y } #[inline(always)] pub fn rem(x: T, y: T) -> T { x % y } @@ -141,63 +139,71 @@ impl num::One for T { } #[cfg(notest)] -impl ops::Add for T { - #[inline(always)] +impl Add for T { fn add(&self, other: &T) -> T { *self + *other } } #[cfg(notest)] -impl ops::Sub for T { - #[inline(always)] +impl Sub for T { fn sub(&self, other: &T) -> T { *self - *other } } #[cfg(notest)] -impl ops::Mul for T { - #[inline(always)] +impl Mul for T { fn mul(&self, other: &T) -> T { *self * *other } } -#[cfg(notest)] -impl ops::Div for T { - #[inline(always)] +#[cfg(stage0,notest)] +impl Div for T { fn div(&self, other: &T) -> T { *self / *other } } -#[cfg(notest)] -impl ops::Modulo for T { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Quot for T { #[inline(always)] + fn quot(&self, other: &T) -> T { *self / *other } +} +#[cfg(stage0,notest)] +impl Modulo for T { fn modulo(&self, other: &T) -> T { *self % *other } } -#[cfg(notest)] -impl ops::Neg for T { +#[cfg(stage1,notest)] +#[cfg(stage2,notest)] +#[cfg(stage3,notest)] +impl Rem for T { #[inline(always)] + fn rem(&self, other: &T) -> T { *self % *other } +} +#[cfg(notest)] +impl Neg for T { fn neg(&self) -> T { -*self } } #[cfg(notest)] -impl ops::BitOr for T { +impl BitOr for T { #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } #[cfg(notest)] -impl ops::BitAnd for T { +impl BitAnd for T { #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } #[cfg(notest)] -impl ops::BitXor for T { +impl BitXor for T { #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } #[cfg(notest)] -impl ops::Shl for T { +impl Shl for T { #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } #[cfg(notest)] -impl ops::Shr for T { +impl Shr for T { #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } #[cfg(notest)] -impl ops::Not for T { +impl Not for T { #[inline(always)] fn not(&self) -> T { !*self } } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 4d89d8a957c7b..465a9330f74c0 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -31,14 +31,30 @@ pub trait Mul { } #[lang="div"] +#[cfg(stage0)] pub trait Div { fn div(&self, rhs: &RHS) -> Result; } +#[lang="quot"] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub trait Quot { + fn quot(&self, rhs: &RHS) -> Result; +} #[lang="modulo"] +#[cfg(stage0)] pub trait Modulo { fn modulo(&self, rhs: &RHS) -> Result; } +#[lang="rem"] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub trait Rem { + fn rem(&self, rhs: &RHS) -> Result; +} #[lang="neg"] pub trait Neg { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 822fb2e476beb..7d8b3edcab152 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -14,7 +14,12 @@ 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)] +pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not}; pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{Drop}; pub use ops::{Shl, Shr, Index}; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 5148ea7fba403..c1cc01ed05a72 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -283,7 +283,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr) add => Ok(const_float(a + b)), subtract => Ok(const_float(a - b)), mul => Ok(const_float(a * b)), - div => Ok(const_float(a / b)), + quot => Ok(const_float(a / b)), rem => Ok(const_float(a % b)), eq => fromb(a == b), lt => fromb(a < b), @@ -299,9 +299,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr) add => Ok(const_int(a + b)), subtract => Ok(const_int(a - b)), mul => Ok(const_int(a * b)), - div if b == 0 => Err(~"divide by zero"), - div => Ok(const_int(a / b)), - rem if b == 0 => Err(~"modulo zero"), + quot if b == 0 => Err(~"quotient zero"), + quot => Ok(const_int(a / b)), + rem if b == 0 => Err(~"remainder zero"), rem => Ok(const_int(a % b)), and | bitand => Ok(const_int(a & b)), or | bitor => Ok(const_int(a | b)), @@ -321,9 +321,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr) add => Ok(const_uint(a + b)), subtract => Ok(const_uint(a - b)), mul => Ok(const_uint(a * b)), - div if b == 0 => Err(~"divide by zero"), - div => Ok(const_uint(a / b)), - rem if b == 0 => Err(~"modulo zero"), + quot if b == 0 => Err(~"quotient zero"), + quot => Ok(const_uint(a / b)), + rem if b == 0 => Err(~"remainder zero"), rem => Ok(const_uint(a % b)), and | bitand => Ok(const_uint(a & b)), or | bitor => Ok(const_uint(a | b)), diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 390ffded2fe36..0558df60b7303 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -480,7 +480,7 @@ pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool { /// This is rather subtle. When we are casting a value to a instantiated /// trait like `a as trait<'r>`, regionck already ensures that any borrowed -/// pointers that appear in the type of `a` are bounded by `'r` (ed.: modulo +/// pointers that appear in the type of `a` are bounded by `'r` (ed.: rem /// FIXME(#5723)). However, it is possible that there are *type parameters* /// in the type of `a`, and those *type parameters* may have borrowed pointers /// within them. We have to guarantee that the regions which appear in those diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 435cb896ac7a1..5b302108ef062 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -45,8 +45,8 @@ pub enum LangItem { AddTraitLangItem, // 5 SubTraitLangItem, // 6 MulTraitLangItem, // 7 - DivTraitLangItem, // 8 - ModuloTraitLangItem, // 9 + QuotTraitLangItem, // 8 + RemTraitLangItem, // 9 NegTraitLangItem, // 10 NotTraitLangItem, // 11 BitXorTraitLangItem, // 12 @@ -108,8 +108,8 @@ pub impl LanguageItems { 5 => "add", 6 => "sub", 7 => "mul", - 8 => "div", - 9 => "modulo", + 8 => "quot", + 9 => "rem", 10 => "neg", 11 => "not", 12 => "bitxor", @@ -170,11 +170,11 @@ pub impl LanguageItems { pub fn mul_trait(&const self) -> def_id { self.items[MulTraitLangItem as uint].get() } - pub fn div_trait(&const self) -> def_id { - self.items[DivTraitLangItem as uint].get() + pub fn quot_trait(&const self) -> def_id { + self.items[QuotTraitLangItem as uint].get() } - pub fn modulo_trait(&const self) -> def_id { - self.items[ModuloTraitLangItem as uint].get() + pub fn rem_trait(&const self) -> def_id { + self.items[RemTraitLangItem as uint].get() } pub fn neg_trait(&const self) -> def_id { self.items[NegTraitLangItem as uint].get() @@ -271,8 +271,8 @@ fn LanguageItemCollector<'r>(crate: @crate, item_refs.insert(@~"add", AddTraitLangItem as uint); item_refs.insert(@~"sub", SubTraitLangItem as uint); item_refs.insert(@~"mul", MulTraitLangItem as uint); - item_refs.insert(@~"div", DivTraitLangItem as uint); - item_refs.insert(@~"modulo", ModuloTraitLangItem as uint); + item_refs.insert(@~"quot", QuotTraitLangItem as uint); + item_refs.insert(@~"rem", RemTraitLangItem as uint); item_refs.insert(@~"neg", NegTraitLangItem as uint); item_refs.insert(@~"not", NotTraitLangItem as uint); item_refs.insert(@~"bitxor", BitXorTraitLangItem as uint); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3c158c0d081f8..41b372119cd29 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -37,7 +37,7 @@ use syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op}; use syntax::ast::{expr_binary, expr_break, expr_field}; use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path}; use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param}; -use syntax::ast::{def_upvar, def_use, def_variant, div, eq}; +use syntax::ast::{def_upvar, def_use, def_variant, quot, eq}; use syntax::ast::{expr, expr_again, expr_assign_op}; use syntax::ast::{expr_index, expr_loop}; use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl}; @@ -4899,13 +4899,13 @@ pub impl Resolver { self.add_fixed_trait_for_expr(expr.id, self.lang_items.mul_trait()); } - expr_binary(div, _, _) | expr_assign_op(div, _, _) => { + expr_binary(quot, _, _) | expr_assign_op(quot, _, _) => { self.add_fixed_trait_for_expr(expr.id, - self.lang_items.div_trait()); + self.lang_items.quot_trait()); } expr_binary(rem, _, _) | expr_assign_op(rem, _, _) => { self.add_fixed_trait_for_expr(expr.id, - self.lang_items.modulo_trait()); + self.lang_items.rem_trait()); } expr_binary(bitxor, _, _) | expr_assign_op(bitxor, _, _) => { self.add_fixed_trait_for_expr(expr.id, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index e1c60234f0ff0..3ad021b2f518f 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -782,12 +782,12 @@ pub fn cast_shift_rhs(op: ast::binop, } } -pub fn fail_if_zero(cx: block, span: span, divmod: ast::binop, +pub fn fail_if_zero(cx: block, span: span, quotrem: ast::binop, rhs: ValueRef, rhs_t: ty::t) -> block { - let text = if divmod == ast::div { - @~"divide by zero" + let text = if quotrem == ast::quot { + @~"quotient zero" } else { - @~"modulo zero" + @~"remainder zero" }; let is_zero = match ty::get(rhs_t).sty { ty::ty_int(t) => { diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index c5e708569dc25..d0aeec89750aa 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -272,7 +272,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef { if is_float { llvm::LLVMConstFMul(te1, te2) } else { llvm::LLVMConstMul(te1, te2) } } - ast::div => { + ast::quot => { if is_float { llvm::LLVMConstFDiv(te1, te2) } else if signed { llvm::LLVMConstSDiv(te1, te2) } else { llvm::LLVMConstUDiv(te1, te2) } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index ba6965f0eaea3..4b4d0869a3ed3 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1437,7 +1437,7 @@ fn trans_eager_binop(bcx: block, if is_float { FMul(bcx, lhs, rhs) } else { Mul(bcx, lhs, rhs) } } - ast::div => { + ast::quot => { if is_float { FDiv(bcx, lhs, rhs) } else { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 95d0fa984aea0..033fbecc08b37 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4255,7 +4255,7 @@ pub fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool { ast::add => opcat_add, ast::subtract => opcat_sub, ast::mul => opcat_mult, - ast::div => opcat_mult, + ast::quot => opcat_mult, ast::rem => opcat_mult, ast::and => opcat_logic, ast::or => opcat_logic, diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index e90f0fb3c81d4..cbdd2b19d276c 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, modulo padding. + * Every 4 encoded characters is converted into 3 octets, rem padding. * * *Example*: * diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs index ec5d2cded8d56..08c65d190bf99 100644 --- a/src/libstd/num/bigint.rs +++ b/src/libstd/num/bigint.rs @@ -262,16 +262,16 @@ impl Mul for BigUint { } } -impl Div for BigUint { - fn div(&self, other: &BigUint) -> BigUint { - let (d, _) = self.divmod(other); +impl Quot for BigUint { + fn quot(&self, other: &BigUint) -> BigUint { + let (d, _) = self.quot_rem(other); return d; } } -impl Modulo for BigUint { - fn modulo(&self, other: &BigUint) -> BigUint { - let (_, m) = self.divmod(other); +impl Rem for BigUint { + fn rem(&self, other: &BigUint) -> BigUint { + let (_, m) = self.quot_rem(other); return m; } } @@ -304,7 +304,7 @@ impl ToStrRadix for BigUint { let mut result = ~[]; let mut r = n; while r > divider { - let (d, r0) = r.divmod(÷r); + let (d, r0) = r.quot_rem(÷r); result += [r0.to_uint() as BigDigit]; r = d; } @@ -384,7 +384,7 @@ pub impl BigUint { fn abs(&self) -> BigUint { copy *self } - fn divmod(&self, other: &BigUint) -> (BigUint, BigUint) { + fn quot_rem(&self, other: &BigUint) -> (BigUint, BigUint) { if other.is_zero() { fail!() } if self.is_zero() { return (Zero::zero(), Zero::zero()); } if *other == One::one() { return (copy *self, Zero::zero()); } @@ -402,10 +402,10 @@ pub impl BigUint { shift += 1; } assert!(shift < BigDigit::bits); - let (d, m) = divmod_inner(self << shift, other << shift); + let (d, m) = quot_rem_inner(self << shift, other << shift); return (d, m >> shift); - fn divmod_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) { + fn quot_rem_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) { let mut r = a; let mut d = Zero::zero::(); let mut n = 1; @@ -464,7 +464,7 @@ pub impl BigUint { return r; } fn quotrem(&self, other: &BigUint) -> (BigUint, BigUint) { - self.divmod(other) + self.quot_rem(other) } fn is_zero(&self) -> bool { self.data.is_empty() } @@ -737,16 +737,16 @@ impl Mul for BigInt { } } -impl Div for BigInt { - fn div(&self, other: &BigInt) -> BigInt { - let (d, _) = self.divmod(other); +impl Quot for BigInt { + fn quot(&self, other: &BigInt) -> BigInt { + let (d, _) = self.quot_rem(other); return d; } } -impl Modulo for BigInt { - fn modulo(&self, other: &BigInt) -> BigInt { - let (_, m) = self.divmod(other); +impl Rem for BigInt { + fn rem(&self, other: &BigInt) -> BigInt { + let (_, m) = self.quot_rem(other); return m; } } @@ -841,9 +841,9 @@ pub impl BigInt { BigInt::from_biguint(Plus, copy self.data) } - fn divmod(&self, other: &BigInt) -> (BigInt, BigInt) { + fn quot_rem(&self, other: &BigInt) -> (BigInt, BigInt) { // m.sign == other.sign - let (d_ui, m_ui) = self.data.divmod(&other.data); + let (d_ui, m_ui) = self.data.quot_rem(&other.data); let d = BigInt::from_biguint(Plus, d_ui), m = BigInt::from_biguint(Plus, m_ui); match (self.sign, other.sign) { @@ -1150,7 +1150,7 @@ mod biguint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - static divmod_quadruples: &'static [(&'static [BigDigit], + static quot_rem_quadruples: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] @@ -1174,7 +1174,7 @@ mod biguint_tests { assert!(b * a == c); } - for divmod_quadruples.each |elm| { + for quot_rem_quadruples.each |elm| { let (aVec, bVec, cVec, dVec) = *elm; let a = BigUint::from_slice(aVec); let b = BigUint::from_slice(bVec); @@ -1187,7 +1187,7 @@ mod biguint_tests { } #[test] - fn test_divmod() { + fn test_quot_rem() { for mul_triples.each |elm| { let (aVec, bVec, cVec) = *elm; let a = BigUint::from_slice(aVec); @@ -1195,21 +1195,21 @@ mod biguint_tests { let c = BigUint::from_slice(cVec); if a.is_not_zero() { - assert!(c.divmod(&a) == (b, Zero::zero())); + assert!(c.quot_rem(&a) == (b, Zero::zero())); } if b.is_not_zero() { - assert!(c.divmod(&b) == (a, Zero::zero())); + assert!(c.quot_rem(&b) == (a, Zero::zero())); } } - for divmod_quadruples.each |elm| { + for quot_rem_quadruples.each |elm| { let (aVec, bVec, cVec, dVec) = *elm; let a = BigUint::from_slice(aVec); let b = BigUint::from_slice(bVec); let c = BigUint::from_slice(cVec); let d = BigUint::from_slice(dVec); - if b.is_not_zero() { assert!(a.divmod(&b) == (c, d)); } + if b.is_not_zero() { assert!(a.quot_rem(&b) == (c, d)); } } } @@ -1516,7 +1516,7 @@ mod bigint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - static divmod_quadruples: &'static [(&'static [BigDigit], + static quot_rem_quadruples: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] @@ -1543,7 +1543,7 @@ mod bigint_tests { assert!((-b) * a == -c); } - for divmod_quadruples.each |elm| { + for quot_rem_quadruples.each |elm| { let (aVec, bVec, cVec, dVec) = *elm; let a = BigInt::from_slice(Plus, aVec); let b = BigInt::from_slice(Plus, bVec); @@ -1556,9 +1556,9 @@ mod bigint_tests { } #[test] - fn test_divmod() { + fn test_quot_rem() { fn check_sub(a: &BigInt, b: &BigInt, ans_d: &BigInt, ans_m: &BigInt) { - let (d, m) = a.divmod(b); + let (d, m) = a.quot_rem(b); if m.is_not_zero() { assert!(m.sign == b.sign); } @@ -1592,7 +1592,7 @@ mod bigint_tests { if b.is_not_zero() { check(&c, &b, &a, &Zero::zero()); } } - for divmod_quadruples.each |elm| { + for quot_rem_quadruples.each |elm| { let (aVec, bVec, cVec, dVec) = *elm; let a = BigInt::from_slice(Plus, aVec); let b = BigInt::from_slice(Plus, bVec); @@ -1635,7 +1635,7 @@ mod bigint_tests { if b.is_not_zero() { check(&c, &b, &a, &Zero::zero()); } } - for divmod_quadruples.each |elm| { + for quot_rem_quadruples.each |elm| { let (aVec, bVec, cVec, dVec) = *elm; let a = BigInt::from_slice(Plus, aVec); let b = BigInt::from_slice(Plus, bVec); diff --git a/src/libstd/num/complex.rs b/src/libstd/num/complex.rs index 949850f3ca677..ef7fa397d7f1b 100644 --- a/src/libstd/num/complex.rs +++ b/src/libstd/num/complex.rs @@ -32,8 +32,7 @@ pub type Complex = Cmplx; pub type Complex32 = Cmplx; pub type Complex64 = Cmplx; -impl + Sub + Mul + Div + Neg> - Cmplx { +impl Cmplx { /// Create a new Cmplx #[inline] pub fn new(re: T, im: T) -> Cmplx { @@ -80,24 +79,21 @@ impl + Sub + Mul + Div + Neg> /* arithmetic */ // (a + i b) + (c + i d) == (a + c) + i (b + d) -impl + Sub + Mul + Div + Neg> - Add, Cmplx> for Cmplx { +impl Add, Cmplx> for Cmplx { #[inline] fn add(&self, other: &Cmplx) -> Cmplx { Cmplx::new(self.re + other.re, self.im + other.im) } } // (a + i b) - (c + i d) == (a - c) + i (b - d) -impl + Sub + Mul + Div + Neg> - Sub, Cmplx> for Cmplx { +impl Sub, Cmplx> for Cmplx { #[inline] fn sub(&self, other: &Cmplx) -> Cmplx { Cmplx::new(self.re - other.re, self.im - other.im) } } // (a + i b) * (c + i d) == (a*c - b*d) + i (a*d + b*c) -impl + Sub + Mul + Div + Neg> - Mul, Cmplx> for Cmplx { +impl Mul, Cmplx> for Cmplx { #[inline] fn mul(&self, other: &Cmplx) -> Cmplx { Cmplx::new(self.re*other.re - self.im*other.im, @@ -107,18 +103,16 @@ impl + Sub + Mul + Div + Neg> // (a + i b) / (c + i d) == [(a + i b) * (c - i d)] / (c*c + d*d) // == [(a*c + b*d) / (c*c + d*d)] + i [(b*c - a*d) / (c*c + d*d)] -impl + Sub + Mul + Div + Neg> - Div, Cmplx> for Cmplx { +impl Quot, Cmplx> for Cmplx { #[inline] - fn div(&self, other: &Cmplx) -> Cmplx { + fn quot(&self, other: &Cmplx) -> Cmplx { let norm_sqr = other.norm_sqr(); Cmplx::new((self.re*other.re + self.im*other.im) / norm_sqr, (self.im*other.re - self.re*other.im) / norm_sqr) } } -impl + Sub + Mul + Div + Neg> - Neg> for Cmplx { +impl Neg> for Cmplx { #[inline] fn neg(&self) -> Cmplx { Cmplx::new(-self.re, -self.im) @@ -126,16 +120,14 @@ impl + Sub + Mul + Div + Neg> } /* constants */ -impl + Sub + Mul + Div + Neg + Zero> - Zero for Cmplx { +impl Zero for Cmplx { #[inline] fn zero() -> Cmplx { Cmplx::new(Zero::zero(), Zero::zero()) } } -impl + Sub + Mul + Div + Neg + Zero + One> - One for Cmplx { +impl One for Cmplx { #[inline] fn one() -> Cmplx { Cmplx::new(One::one(), Zero::zero()) @@ -143,7 +135,7 @@ impl + Sub + Mul + Div + Neg + Zero + One> } /* string conversions */ -impl> ToStr for Cmplx { +impl ToStr for Cmplx { fn to_str(&self) -> ~str { if self.im < Zero::zero() { fmt!("%s-%si", self.re.to_str(), (-self.im).to_str()) @@ -153,7 +145,7 @@ impl> ToStr for Cmplx { } } -impl> ToStrRadix for Cmplx { +impl ToStrRadix for Cmplx { fn to_str_radix(&self, radix: uint) -> ~str { if self.im < Zero::zero() { fmt!("%s-%si", self.re.to_str_radix(radix), (-self.im).to_str_radix(radix)) @@ -280,7 +272,7 @@ mod test { } } #[test] - fn test_div() { + fn test_quot() { assert_eq!(_neg1_1i / _0_1i, _1_1i); for all_consts.each |&c| { if c != Zero::zero() { diff --git a/src/libstd/num/rational.rs b/src/libstd/num/rational.rs index f15b382dcd351..2098429833dfc 100644 --- a/src/libstd/num/rational.rs +++ b/src/libstd/num/rational.rs @@ -33,7 +33,7 @@ pub type Rational64 = Ratio; /// Alias for arbitrary precision rationals. pub type BigRational = Ratio; -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl Ratio { /// Create a ratio representing the integer `t`. #[inline(always)] @@ -51,7 +51,7 @@ impl + Modulo + Neg + Zero + One + Ord + Eq> #[inline(always)] pub fn new(numer: T, denom: T) -> Ratio { if denom == Zero::zero() { - fail!(~"divide by 0"); + fail!(~"quotient of 0"); } let mut ret = Ratio::new_raw(numer, denom); ret.reduce(); @@ -85,7 +85,7 @@ Compute the greatest common divisor of two numbers, via Euclid's algorithm. The result can be negative. */ #[inline] -pub fn gcd_raw + Zero + Eq>(n: T, m: T) -> T { +pub fn gcd_raw(n: T, m: T) -> T { let mut m = m, n = n; while m != Zero::zero() { let temp = m; @@ -101,7 +101,7 @@ Compute the greatest common divisor of two numbers, via Euclid's algorithm. The result is always positive. */ #[inline] -pub fn gcd + Neg + Zero + Ord + Eq>(n: T, m: T) -> T { +pub fn gcd(n: T, m: T) -> T { let g = gcd_raw(n, m); if g < Zero::zero() { -g } else { g } @@ -136,7 +136,7 @@ cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) /* Arithmetic */ // a/b * c/d = (a*c)/(b*d) -impl + Div + Modulo + Neg + Zero + One + Ord + Eq> +impl Mul,Ratio> for Ratio { #[inline] fn mul(&self, rhs: &Ratio) -> Ratio { @@ -145,10 +145,10 @@ impl + Div + Modulo + Neg + Zero + One + Ord + E } // (a/b) / (c/d) = (a*d)/(b*c) -impl + Div + Modulo + Neg + Zero + One + Ord + Eq> - Div,Ratio> for Ratio { +impl + Quot,Ratio> for Ratio { #[inline] - fn div(&self, rhs: &Ratio) -> Ratio { + fn quot(&self, rhs: &Ratio) -> Ratio { Ratio::new(self.numer * rhs.denom, self.denom * rhs.numer) } } @@ -156,9 +156,7 @@ impl + Div + Modulo + Neg + Zero + One + Ord + E // Abstracts the a/b `op` c/d = (a*d `op` b*d) / (b*d) pattern macro_rules! arith_impl { (impl $imp:ident, $method:ident) => { - impl + Sub + Mul + Div + Modulo + Neg + - Zero + One + Ord + Eq> + impl $imp,Ratio> for Ratio { #[inline] fn $method(&self, rhs: &Ratio) -> Ratio { @@ -176,9 +174,9 @@ arith_impl!(impl Add, add) arith_impl!(impl Sub, sub) // a/b % c/d = (a*d % b*c)/(b*d) -arith_impl!(impl Modulo, modulo) +arith_impl!(impl Rem, rem) -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl Neg> for Ratio { #[inline] fn neg(&self) -> Ratio { @@ -187,7 +185,7 @@ impl + Modulo + Neg + Zero + One + Ord + Eq> } /* Constants */ -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl Zero for Ratio { #[inline] fn zero() -> Ratio { @@ -195,7 +193,7 @@ impl + Modulo + Neg + Zero + One + Ord + Eq> } } -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl One for Ratio { #[inline] fn one() -> Ratio { @@ -204,8 +202,7 @@ impl + Modulo + Neg + Zero + One + Ord + Eq> } /* Utils */ -impl + Sub + Mul + Div + Modulo + Neg + - Zero + One + Ord + Eq> +impl Round for Ratio { fn round(&self, mode: num::RoundMode) -> Ratio { match mode { @@ -256,7 +253,7 @@ impl ToStrRadix for Ratio { } } -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl FromStr for Ratio { /// Parses `numer/denom`. fn from_str(s: &str) -> Option> { @@ -273,7 +270,7 @@ impl + Modulo + Neg + Zero + One + Ord + Eq } } } -impl + Modulo + Neg + Zero + One + Ord + Eq> +impl FromStrRadix for Ratio { /// Parses `numer/denom` where the numbers are in base `radix`. fn from_str_radix(s: &str, radix: uint) -> Option> { @@ -386,14 +383,14 @@ mod test { } #[test] - fn test_div() { + fn test_quot() { assert_eq!(_1 / _1_2, _2); assert_eq!(_3_2 / _1_2, _1 + _2); assert_eq!(_1 / _neg1_2, _neg1_2 + _neg1_2 + _neg1_2 + _neg1_2); } #[test] - fn test_modulo() { + fn test_rem() { assert_eq!(_3_2 % _1, _1_2); assert_eq!(_2 % _neg1_2, _0); assert_eq!(_1_2 % _2, _1_2); @@ -415,7 +412,7 @@ mod test { } #[test] #[should_fail] - fn test_div_0() { + fn test_quot_0() { let _a = _1 / _0; } } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 3dfc3200f0f52..7bedef0f84110 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -98,10 +98,19 @@ pub mod cmp; pub mod base64; pub mod rl; pub mod workcache; +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] #[path="num/bigint.rs"] pub mod bigint; +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] #[path="num/rational.rs"] pub mod rational; +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] #[path="num/complex.rs"] pub mod complex; pub mod stats; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b0b3e45abe501..a086a1db0aaf1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -389,7 +389,7 @@ pub enum binop { add, subtract, mul, - div, + quot, rem, and, or, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 910c9857d2d63..f0a14b39049a8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -80,7 +80,7 @@ pub fn binop_to_str(op: binop) -> ~str { add => return ~"+", subtract => return ~"-", mul => return ~"*", - div => return ~"/", + quot => return ~"/", rem => return ~"%", and => return ~"&&", or => return ~"||", @@ -103,8 +103,8 @@ pub fn binop_to_method_name(op: binop) -> Option<~str> { add => return Some(~"add"), subtract => return Some(~"sub"), mul => return Some(~"mul"), - div => return Some(~"div"), - rem => return Some(~"modulo"), + quot => return Some(~"quot"), + rem => return Some(~"rem"), bitxor => return Some(~"bitxor"), bitand => return Some(~"bitand"), bitor => return Some(~"bitor"), @@ -348,7 +348,7 @@ pub fn is_self(d: ast::def) -> bool { /// Maps a binary operator to its precedence pub fn operator_prec(op: ast::binop) -> uint { match op { - mul | div | rem => 12u, + mul | quot | rem => 12u, // 'as' sits between here with 11 add | subtract => 10u, shl | shr => 9u, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e892f212b0577..42275aca0a3e2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -21,7 +21,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; use ast::{blk_check_mode, box, by_copy, by_ref}; use ast::{crate, crate_cfg, decl, decl_item}; -use ast::{decl_local, default_blk, deref, div, enum_def}; +use ast::{decl_local, default_blk, deref, quot, enum_def}; use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; @@ -1786,7 +1786,7 @@ pub impl Parser { token::PLUS => aop = add, token::MINUS => aop = subtract, token::STAR => aop = mul, - token::SLASH => aop = div, + token::SLASH => aop = quot, token::PERCENT => aop = rem, token::CARET => aop = bitxor, token::AND => aop = bitand, diff --git a/src/libsyntax/parse/prec.rs b/src/libsyntax/parse/prec.rs index 79adabec9b773..d8c829740fa3f 100644 --- a/src/libsyntax/parse/prec.rs +++ b/src/libsyntax/parse/prec.rs @@ -31,7 +31,7 @@ pub static as_prec: uint = 11u; pub fn token_to_binop(tok: Token) -> Option { match tok { BINOP(STAR) => Some(mul), - BINOP(SLASH) => Some(div), + BINOP(SLASH) => Some(quot), BINOP(PERCENT) => Some(rem), // 'as' sits between here with 11 BINOP(PLUS) => Some(add), diff --git a/src/test/compile-fail/eval-enum.rs b/src/test/compile-fail/eval-enum.rs index d8443f836f50a..d368f9d6769de 100644 --- a/src/test/compile-fail/eval-enum.rs +++ b/src/test/compile-fail/eval-enum.rs @@ -1,6 +1,6 @@ enum test { - div_zero = 1/0, //~ERROR expected constant: divide by zero - rem_zero = 1%0 //~ERROR expected constant: modulo zero + quot_zero = 1/0, //~ERROR expected constant: quotient zero + rem_zero = 1%0 //~ERROR expected constant: remainder zero } fn main() {} diff --git a/src/test/run-fail/divide-by-zero.rs b/src/test/run-fail/divide-by-zero.rs index 6bad7ab194acd..7a17dd024153c 100644 --- a/src/test/run-fail/divide-by-zero.rs +++ b/src/test/run-fail/divide-by-zero.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:divide by zero +// error-pattern:quotient zero fn main() { let y = 0; let z = 1 / y; diff --git a/src/test/run-fail/mod-zero.rs b/src/test/run-fail/mod-zero.rs index 05ff7bd96bdf8..c379a8fc65fd7 100644 --- a/src/test/run-fail/mod-zero.rs +++ b/src/test/run-fail/mod-zero.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:modulo zero +// error-pattern:remainder zero fn main() { let y = 0; let z = 1 % y;