: 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`
: 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
## 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.
<item> Add </item>
<item> Sub </item>
<item> Mul </item>
- <item> Div </item>
- <item> Modulo </item>
+ <item> Quot </item>
+ <item> Rem </item>
<item> Neg </item>
<item> BitAnd </item>
<item> BitOr </item>
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
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};
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::*;
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; }
}
#[cfg(notest)]
-impl cmp::Eq for f32 {
+impl Eq for f32 {
#[inline(always)]
fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
#[inline(always)]
}
#[cfg(notest)]
-impl cmp::Ord for f32 {
+impl Ord for f32 {
#[inline(always)]
fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
#[inline(always)]
}
#[cfg(notest)]
-impl ops::Add<f32,f32> for f32 {
- #[inline(always)]
+impl Add<f32,f32> for f32 {
fn add(&self, other: &f32) -> f32 { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub<f32,f32> for f32 {
- #[inline(always)]
+impl Sub<f32,f32> for f32 {
fn sub(&self, other: &f32) -> f32 { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul<f32,f32> for f32 {
- #[inline(always)]
+impl Mul<f32,f32> for f32 {
fn mul(&self, other: &f32) -> f32 { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div<f32,f32> for f32 {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div<f32,f32> for f32 {
fn div(&self, other: &f32) -> f32 { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo<f32,f32> for f32 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot<f32,f32> for f32 {
#[inline(always)]
+ fn quot(&self, other: &f32) -> f32 { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo<f32,f32> for f32 {
fn modulo(&self, other: &f32) -> f32 { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg<f32> for f32 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem<f32,f32> for f32 {
#[inline(always)]
+ fn rem(&self, other: &f32) -> f32 { *self % *other }
+}
+#[cfg(notest)]
+impl Neg<f32> for f32 {
fn neg(&self) -> f32 { -*self }
}
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};
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; }
}
#[cfg(notest)]
-impl cmp::Eq for f64 {
+impl Eq for f64 {
#[inline(always)]
fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
#[inline(always)]
}
#[cfg(notest)]
-impl cmp::Ord for f64 {
+impl Ord for f64 {
#[inline(always)]
fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
#[inline(always)]
}
#[cfg(notest)]
-impl ops::Add<f64,f64> for f64 {
- #[inline(always)]
+impl Add<f64,f64> for f64 {
fn add(&self, other: &f64) -> f64 { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub<f64,f64> for f64 {
- #[inline(always)]
+impl Sub<f64,f64> for f64 {
fn sub(&self, other: &f64) -> f64 { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul<f64,f64> for f64 {
- #[inline(always)]
+impl Mul<f64,f64> for f64 {
fn mul(&self, other: &f64) -> f64 { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div<f64,f64> for f64 {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div<f64,f64> for f64 {
fn div(&self, other: &f64) -> f64 { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo<f64,f64> for f64 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot<f64,f64> for f64 {
#[inline(always)]
+ fn quot(&self, other: &f64) -> f64 { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo<f64,f64> for f64 {
fn modulo(&self, other: &f64) -> f64 { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg<f64> for f64 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem<f64,f64> for f64 {
#[inline(always)]
+ fn rem(&self, other: &f64) -> f64 { *self % *other }
+}
+#[cfg(notest)]
+impl Neg<f64> for f64 {
fn neg(&self) -> f64 { -*self }
}
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};
}
#[cfg(notest)]
-impl ops::Add<float,float> for float {
- #[inline(always)]
+impl Add<float,float> for float {
fn add(&self, other: &float) -> float { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub<float,float> for float {
- #[inline(always)]
+impl Sub<float,float> for float {
fn sub(&self, other: &float) -> float { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul<float,float> for float {
- #[inline(always)]
+impl Mul<float,float> for float {
fn mul(&self, other: &float) -> float { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div<float,float> for float {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div<float,float> for float {
fn div(&self, other: &float) -> float { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo<float,float> for float {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot<float,float> for float {
#[inline(always)]
+ fn quot(&self, other: &float) -> float { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo<float,float> for float {
fn modulo(&self, other: &float) -> float { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg<float> for float {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem<float,float> for float {
#[inline(always)]
+ fn rem(&self, other: &float) -> float { *self % *other }
+}
+#[cfg(notest)]
+impl Neg<float> for float {
fn neg(&self) -> float { -*self }
}
use num;
use prelude::*;
-#[cfg(notest)] use cmp::{Eq, Ord};
-
pub use cmp::{min, max};
pub static bits : uint = inst::bits;
#[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.
}
#[cfg(notest)]
-impl ops::Add<T,T> for T {
- #[inline(always)]
+impl Add<T,T> for T {
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub<T,T> for T {
- #[inline(always)]
+impl Sub<T,T> for T {
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul<T,T> for T {
- #[inline(always)]
+impl Mul<T,T> for T {
fn mul(&self, other: &T) -> T { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div<T,T> for T {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div<T,T> for T {
fn div(&self, other: &T) -> T { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo<T,T> for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot<T,T> for T {
#[inline(always)]
+ fn quot(&self, other: &T) -> T { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo<T,T> for T {
fn modulo(&self, other: &T) -> T { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg<T> for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem<T,T> for T {
#[inline(always)]
+ fn rem(&self, other: &T) -> T { *self % *other }
+}
+#[cfg(notest)]
+impl Neg<T> for T {
fn neg(&self) -> T { -*self }
}
#[cfg(notest)]
-impl ops::BitOr<T,T> for T {
+impl BitOr<T,T> for T {
#[inline(always)]
fn bitor(&self, other: &T) -> T { *self | *other }
}
#[cfg(notest)]
-impl ops::BitAnd<T,T> for T {
+impl BitAnd<T,T> for T {
#[inline(always)]
fn bitand(&self, other: &T) -> T { *self & *other }
}
#[cfg(notest)]
-impl ops::BitXor<T,T> for T {
+impl BitXor<T,T> for T {
#[inline(always)]
fn bitxor(&self, other: &T) -> T { *self ^ *other }
}
#[cfg(notest)]
-impl ops::Shl<T,T> for T {
+impl Shl<T,T> for T {
#[inline(always)]
fn shl(&self, other: &T) -> T { *self << *other }
}
#[cfg(notest)]
-impl ops::Shr<T,T> for T {
+impl Shr<T,T> for T {
#[inline(always)]
fn shr(&self, other: &T) -> T { *self >> *other }
}
#[cfg(notest)]
-impl ops::Not<T> for T {
+impl Not<T> for T {
#[inline(always)]
fn not(&self) -> T { !*self }
}
//! 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;
+ Add<Self,Self>
+ Sub<Self,Self>
+ Mul<Self,Self>
- + Div<Self,Self>
- + Modulo<Self,Self> {}
+ + Quot<Self,Self>
+ + Rem<Self,Self> {}
impl Num for u8 {}
impl Num for u16 {}
* - 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<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
+pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Quot<T,T>+Mul<T,T>>(
radix: uint, pow: uint) -> T {
let _0: T = Zero::zero();
let _1: T = One::one();
total
}
-#[cfg(test)]
+#[cfg(stage0,test)]
fn test_num<T:Num + NumCast>(ten: T, two: T) {
assert_eq!(ten.add(&two), cast(12));
assert_eq!(ten.sub(&two), cast(8));
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<T:Num + NumCast>(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) }
// 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;
}
#[inline(always)]
-fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
+fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Quot<T,T>>(num: &T) -> bool {
let _0: T = Zero::zero();
let _1: T = One::one();
* - Fails if `radix` < 2 or `radix` > 36.
*/
pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
- Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
+ Quot<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
if (radix as int) < 2 {
*/
#[inline(always)]
pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
- Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
+ Quot<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
let (bytes, special) = to_str_bytes_common(num, radix,
* - 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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
+pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Quot<T,T>+
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
NumStrConv>(
buf: &[u8], radix: uint, negative: bool, fractional: bool,
* `from_str_bytes_common()`, for details see there.
*/
#[inline(always)]
-pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+Mul<T,T>+
+pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Quot<T,T>+Mul<T,T>+
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv>(
buf: &str, radix: uint, negative: bool, fractional: bool,
special: bool, exponent: ExponentFormat, empty_zero: bool,
use option::Option;
use prelude::*;
-#[cfg(notest)] use cmp::{Eq, Ord};
-
pub use cmp::{min, max};
pub static bits : uint = inst::bits;
#[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 }
}
#[cfg(notest)]
-impl ops::Add<T,T> for T {
- #[inline(always)]
+impl Add<T,T> for T {
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub<T,T> for T {
- #[inline(always)]
+impl Sub<T,T> for T {
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul<T,T> for T {
- #[inline(always)]
+impl Mul<T,T> for T {
fn mul(&self, other: &T) -> T { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div<T,T> for T {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div<T,T> for T {
fn div(&self, other: &T) -> T { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo<T,T> for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot<T,T> for T {
#[inline(always)]
+ fn quot(&self, other: &T) -> T { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo<T,T> for T {
fn modulo(&self, other: &T) -> T { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg<T> for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem<T,T> for T {
#[inline(always)]
+ fn rem(&self, other: &T) -> T { *self % *other }
+}
+#[cfg(notest)]
+impl Neg<T> for T {
fn neg(&self) -> T { -*self }
}
#[cfg(notest)]
-impl ops::BitOr<T,T> for T {
+impl BitOr<T,T> for T {
#[inline(always)]
fn bitor(&self, other: &T) -> T { *self | *other }
}
#[cfg(notest)]
-impl ops::BitAnd<T,T> for T {
+impl BitAnd<T,T> for T {
#[inline(always)]
fn bitand(&self, other: &T) -> T { *self & *other }
}
#[cfg(notest)]
-impl ops::BitXor<T,T> for T {
+impl BitXor<T,T> for T {
#[inline(always)]
fn bitxor(&self, other: &T) -> T { *self ^ *other }
}
#[cfg(notest)]
-impl ops::Shl<T,T> for T {
+impl Shl<T,T> for T {
#[inline(always)]
fn shl(&self, other: &T) -> T { *self << *other }
}
#[cfg(notest)]
-impl ops::Shr<T,T> for T {
+impl Shr<T,T> for T {
#[inline(always)]
fn shr(&self, other: &T) -> T { *self >> *other }
}
#[cfg(notest)]
-impl ops::Not<T> for T {
+impl Not<T> for T {
#[inline(always)]
fn not(&self) -> T { !*self }
}
}
#[lang="div"]
+#[cfg(stage0)]
pub trait Div<RHS,Result> {
fn div(&self, rhs: &RHS) -> Result;
}
+#[lang="quot"]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub trait Quot<RHS,Result> {
+ fn quot(&self, rhs: &RHS) -> Result;
+}
#[lang="modulo"]
+#[cfg(stage0)]
pub trait Modulo<RHS,Result> {
fn modulo(&self, rhs: &RHS) -> Result;
}
+#[lang="rem"]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub trait Rem<RHS,Result> {
+ fn rem(&self, rhs: &RHS) -> Result;
+}
#[lang="neg"]
pub trait Neg<Result> {
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};
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),
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)),
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)),
/// 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
AddTraitLangItem, // 5
SubTraitLangItem, // 6
MulTraitLangItem, // 7
- DivTraitLangItem, // 8
- ModuloTraitLangItem, // 9
+ QuotTraitLangItem, // 8
+ RemTraitLangItem, // 9
NegTraitLangItem, // 10
NotTraitLangItem, // 11
BitXorTraitLangItem, // 12
5 => "add",
6 => "sub",
7 => "mul",
- 8 => "div",
- 9 => "modulo",
+ 8 => "quot",
+ 9 => "rem",
10 => "neg",
11 => "not",
12 => "bitxor",
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()
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);
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};
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,
}
}
-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) => {
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) }
if is_float { FMul(bcx, lhs, rhs) }
else { Mul(bcx, lhs, rhs) }
}
- ast::div => {
+ ast::quot => {
if is_float {
FDiv(bcx, lhs, rhs)
} else {
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,
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*:
*
}
}
-impl Div<BigUint, BigUint> for BigUint {
- fn div(&self, other: &BigUint) -> BigUint {
- let (d, _) = self.divmod(other);
+impl Quot<BigUint, BigUint> for BigUint {
+ fn quot(&self, other: &BigUint) -> BigUint {
+ let (d, _) = self.quot_rem(other);
return d;
}
}
-impl Modulo<BigUint, BigUint> for BigUint {
- fn modulo(&self, other: &BigUint) -> BigUint {
- let (_, m) = self.divmod(other);
+impl Rem<BigUint, BigUint> for BigUint {
+ fn rem(&self, other: &BigUint) -> BigUint {
+ let (_, m) = self.quot_rem(other);
return m;
}
}
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;
}
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()); }
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::<BigUint>();
let mut n = 1;
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() }
}
}
-impl Div<BigInt, BigInt> for BigInt {
- fn div(&self, other: &BigInt) -> BigInt {
- let (d, _) = self.divmod(other);
+impl Quot<BigInt, BigInt> for BigInt {
+ fn quot(&self, other: &BigInt) -> BigInt {
+ let (d, _) = self.quot_rem(other);
return d;
}
}
-impl Modulo<BigInt, BigInt> for BigInt {
- fn modulo(&self, other: &BigInt) -> BigInt {
- let (_, m) = self.divmod(other);
+impl Rem<BigInt, BigInt> for BigInt {
+ fn rem(&self, other: &BigInt) -> BigInt {
+ let (_, m) = self.quot_rem(other);
return m;
}
}
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) {
(&[ 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])]
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);
}
#[test]
- fn test_divmod() {
+ fn test_quot_rem() {
for mul_triples.each |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
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)); }
}
}
(&[ 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])]
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);
}
#[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);
}
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);
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);
pub type Complex32 = Cmplx<f32>;
pub type Complex64 = Cmplx<f64>;
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Cmplx<T> {
+impl<T: Copy + Num> Cmplx<T> {
/// Create a new Cmplx
#[inline]
pub fn new(re: T, im: T) -> Cmplx<T> {
/* arithmetic */
// (a + i b) + (c + i d) == (a + c) + i (b + d)
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Add<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Add<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
#[inline]
fn add(&self, other: &Cmplx<T>) -> Cmplx<T> {
Cmplx::new(self.re + other.re, self.im + other.im)
}
}
// (a + i b) - (c + i d) == (a - c) + i (b - d)
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Sub<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Sub<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
#[inline]
fn sub(&self, other: &Cmplx<T>) -> Cmplx<T> {
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<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Mul<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Mul<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
#[inline]
fn mul(&self, other: &Cmplx<T>) -> Cmplx<T> {
Cmplx::new(self.re*other.re - self.im*other.im,
// (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<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Div<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Quot<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
#[inline]
- fn div(&self, other: &Cmplx<T>) -> Cmplx<T> {
+ fn quot(&self, other: &Cmplx<T>) -> Cmplx<T> {
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<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>
- Neg<Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Neg<Cmplx<T>> for Cmplx<T> {
#[inline]
fn neg(&self) -> Cmplx<T> {
Cmplx::new(-self.re, -self.im)
}
/* constants */
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T> + Zero>
- Zero for Cmplx<T> {
+impl<T: Copy + Num> Zero for Cmplx<T> {
#[inline]
fn zero() -> Cmplx<T> {
Cmplx::new(Zero::zero(), Zero::zero())
}
}
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T> + Zero + One>
- One for Cmplx<T> {
+impl<T: Copy + Num> One for Cmplx<T> {
#[inline]
fn one() -> Cmplx<T> {
Cmplx::new(One::one(), Zero::zero())
}
/* string conversions */
-impl<T: ToStr + Zero + Ord + Neg<T>> ToStr for Cmplx<T> {
+impl<T: ToStr + Num + Ord> ToStr for Cmplx<T> {
fn to_str(&self) -> ~str {
if self.im < Zero::zero() {
fmt!("%s-%si", self.re.to_str(), (-self.im).to_str())
}
}
-impl<T: ToStrRadix + Zero + Ord + Neg<T>> ToStrRadix for Cmplx<T> {
+impl<T: ToStrRadix + Num + Ord> ToStrRadix for Cmplx<T> {
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))
}
}
#[test]
- fn test_div() {
+ fn test_quot() {
assert_eq!(_neg1_1i / _0_1i, _1_1i);
for all_consts.each |&c| {
if c != Zero::zero() {
/// Alias for arbitrary precision rationals.
pub type BigRational = Ratio<BigInt>;
-impl<T: Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
Ratio<T> {
/// Create a ratio representing the integer `t`.
#[inline(always)]
#[inline(always)]
pub fn new(numer: T, denom: T) -> Ratio<T> {
if denom == Zero::zero() {
- fail!(~"divide by 0");
+ fail!(~"quotient of 0");
}
let mut ret = Ratio::new_raw(numer, denom);
ret.reduce();
The result can be negative.
*/
#[inline]
-pub fn gcd_raw<T: Modulo<T,T> + Zero + Eq>(n: T, m: T) -> T {
+pub fn gcd_raw<T: Num>(n: T, m: T) -> T {
let mut m = m, n = n;
while m != Zero::zero() {
let temp = m;
The result is always positive.
*/
#[inline]
-pub fn gcd<T: Modulo<T,T> + Neg<T> + Zero + Ord + Eq>(n: T, m: T) -> T {
+pub fn gcd<T: Num + Ord>(n: T, m: T) -> T {
let g = gcd_raw(n, m);
if g < Zero::zero() { -g }
else { g }
/* Arithmetic */
// a/b * c/d = (a*c)/(b*d)
-impl<T: Copy + Mul<T,T> + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
Mul<Ratio<T>,Ratio<T>> for Ratio<T> {
#[inline]
fn mul(&self, rhs: &Ratio<T>) -> Ratio<T> {
}
// (a/b) / (c/d) = (a*d)/(b*c)
-impl<T: Copy + Mul<T,T> + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
- Div<Ratio<T>,Ratio<T>> for Ratio<T> {
+impl<T: Copy + Num + Ord>
+ Quot<Ratio<T>,Ratio<T>> for Ratio<T> {
#[inline]
- fn div(&self, rhs: &Ratio<T>) -> Ratio<T> {
+ fn quot(&self, rhs: &Ratio<T>) -> Ratio<T> {
Ratio::new(self.numer * rhs.denom, self.denom * rhs.numer)
}
}
// 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<T: Copy +
- Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Modulo<T,T> + Neg<T> +
- Zero + One + Ord + Eq>
+ impl<T: Copy + Num + Ord>
$imp<Ratio<T>,Ratio<T>> for Ratio<T> {
#[inline]
fn $method(&self, rhs: &Ratio<T>) -> Ratio<T> {
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<T: Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
Neg<Ratio<T>> for Ratio<T> {
#[inline]
fn neg(&self) -> Ratio<T> {
}
/* Constants */
-impl<T: Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
Zero for Ratio<T> {
#[inline]
fn zero() -> Ratio<T> {
}
}
-impl<T: Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
One for Ratio<T> {
#[inline]
fn one() -> Ratio<T> {
}
/* Utils */
-impl<T: Copy + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Modulo<T,T> + Neg<T> +
- Zero + One + Ord + Eq>
+impl<T: Copy + Num + Ord>
Round for Ratio<T> {
fn round(&self, mode: num::RoundMode) -> Ratio<T> {
match mode {
}
}
-impl<T: FromStr + Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: FromStr + Copy + Num + Ord>
FromStr for Ratio<T> {
/// Parses `numer/denom`.
fn from_str(s: &str) -> Option<Ratio<T>> {
}
}
}
-impl<T: FromStrRadix + Copy + Div<T,T> + Modulo<T,T> + Neg<T> + Zero + One + Ord + Eq>
+impl<T: FromStrRadix + Copy + Num + Ord>
FromStrRadix for Ratio<T> {
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
}
#[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);
}
#[test]
#[should_fail]
- fn test_div_0() {
+ fn test_quot_0() {
let _a = _1 / _0;
}
}
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;
add,
subtract,
mul,
- div,
+ quot,
rem,
and,
or,
add => return ~"+",
subtract => return ~"-",
mul => return ~"*",
- div => return ~"/",
+ quot => return ~"/",
rem => return ~"%",
and => return ~"&&",
or => return ~"||",
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"),
/// 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,
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};
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,
pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
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),
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() {}
// 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;
// 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;