diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-05-01 15:40:05 +1000 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-05-01 15:40:05 +1000 |
| commit | ee26c7c433dbb8d41a2b65dbc89eb84acfc2d311 (patch) | |
| tree | 3695dcd0a6ef66dcca551d6bb87776694987ee73 /src/libcore/num | |
| parent | 7a857673ff76c966ceb061e3794b119e2e498c40 (diff) | |
| download | rust-ee26c7c433dbb8d41a2b65dbc89eb84acfc2d311.tar.gz rust-ee26c7c433dbb8d41a2b65dbc89eb84acfc2d311.zip | |
Revert rename of Div to Quot
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/f32.rs | 9 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 9 | ||||
| -rw-r--r-- | src/libcore/num/float.rs | 10 | ||||
| -rw-r--r-- | src/libcore/num/int-template.rs | 123 | ||||
| -rw-r--r-- | src/libcore/num/num.rs | 29 | ||||
| -rw-r--r-- | src/libcore/num/strconv.rs | 16 | ||||
| -rw-r--r-- | src/libcore/num/uint-template.rs | 29 |
7 files changed, 99 insertions, 126 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index e687f482fa9..04ddd63a177 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -123,7 +123,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 quot(x: f32, y: f32) -> f32 { return x / y; } +pub fn div(x: f32, y: f32) -> f32 { return x / y; } #[inline(always)] pub fn rem(x: f32, y: f32) -> f32 { return x % y; } @@ -279,16 +279,11 @@ impl Mul<f32,f32> for f32 { fn mul(&self, other: &f32) -> f32 { *self * *other } } -#[cfg(stage0,notest)] +#[cfg(notest)] impl Div<f32,f32> for f32 { #[inline(always)] fn div(&self, other: &f32) -> f32 { *self / *other } } -#[cfg(not(stage0),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 { diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index d00e6ae2c0d..9f1944e3fad 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -149,7 +149,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 quot(x: f64, y: f64) -> f64 { return x / y; } +pub fn div(x: f64, y: f64) -> f64 { return x / y; } #[inline(always)] pub fn rem(x: f64, y: f64) -> f64 { return x % y; } @@ -296,15 +296,10 @@ impl Sub<f64,f64> for f64 { impl Mul<f64,f64> for f64 { fn mul(&self, other: &f64) -> f64 { *self * *other } } -#[cfg(stage0,notest)] +#[cfg(notest)] impl Div<f64,f64> for f64 { fn div(&self, other: &f64) -> f64 { *self / *other } } -#[cfg(not(stage0),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 } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 3aa8848cdbe..f163d67a69c 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -25,7 +25,7 @@ use libc::c_int; use num::{Zero, One, strconv}; use prelude::*; -pub use f64::{add, sub, mul, quot, rem, lt, le, eq, ne, ge, gt}; +pub use f64::{add, sub, mul, div, 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}; @@ -692,16 +692,12 @@ impl Mul<float,float> for float { fn mul(&self, other: &float) -> float { *self * *other } } -#[cfg(stage0,notest)] +#[cfg(notest)] impl Div<float,float> for float { #[inline(always)] fn div(&self, other: &float) -> float { *self / *other } } -#[cfg(not(stage0),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 { #[inline(always)] diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index ec38a32c039..fadba84a0fe 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -30,7 +30,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 quot(x: T, y: T) -> T { x / y } +pub fn div(x: T, y: T) -> T { x / y } /// /// Returns the remainder of y / x. @@ -201,16 +201,11 @@ impl Mul<T,T> for T { fn mul(&self, other: &T) -> T { *self * *other } } -#[cfg(stage0,notest)] +#[cfg(notest)] impl Div<T,T> for T { - #[inline(always)] - fn div(&self, other: &T) -> T { *self / *other } -} -#[cfg(not(stage0),notest)] -impl Quot<T,T> for T { /// - /// Returns the integer quotient, truncated towards 0. As this behaviour reflects - /// the underlying machine implementation it is more efficient than `Natural::div`. + /// Integer division, truncated towards 0. As this behaviour reflects the underlying + /// machine implementation it is more efficient than `Integer::div_floor`. /// /// # Examples /// @@ -227,7 +222,7 @@ impl Quot<T,T> for T { /// ~~~ /// #[inline(always)] - fn quot(&self, other: &T) -> T { *self / *other } + fn div(&self, other: &T) -> T { *self / *other } } #[cfg(stage0,notest)] @@ -307,25 +302,25 @@ impl Integer for T { /// # Examples /// /// ~~~ - /// assert!(( 8).div( 3) == 2); - /// assert!(( 8).div(-3) == -3); - /// assert!((-8).div( 3) == -3); - /// assert!((-8).div(-3) == 2); + /// assert!(( 8).div_floor( 3) == 2); + /// assert!(( 8).div_floor(-3) == -3); + /// assert!((-8).div_floor( 3) == -3); + /// assert!((-8).div_floor(-3) == 2); /// - /// assert!(( 1).div( 2) == 0); - /// assert!(( 1).div(-2) == -1); - /// assert!((-1).div( 2) == -1); - /// assert!((-1).div(-2) == 0); + /// assert!(( 1).div_floor( 2) == 0); + /// assert!(( 1).div_floor(-2) == -1); + /// assert!((-1).div_floor( 2) == -1); + /// assert!((-1).div_floor(-2) == 0); /// ~~~ /// #[inline(always)] - fn div(&self, other: &T) -> T { + fn div_floor(&self, other: &T) -> T { // Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_, // December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf) - match self.quot_rem(other) { - (q, r) if (r > 0 && *other < 0) - || (r < 0 && *other > 0) => q - 1, - (q, _) => q, + match self.div_rem(other) { + (d, r) if (r > 0 && *other < 0) + || (r < 0 && *other > 0) => d - 1, + (d, _) => d, } } @@ -333,25 +328,25 @@ impl Integer for T { /// Integer modulo, satisfying: /// /// ~~~ - /// assert!(n.div(d) * d + n.modulo(d) == n) + /// assert!(n.div_floor(d) * d + n.mod_floor(d) == n) /// ~~~ /// /// # Examples /// /// ~~~ - /// assert!(( 8).modulo( 3) == 2); - /// assert!(( 8).modulo(-3) == -1); - /// assert!((-8).modulo( 3) == 1); - /// assert!((-8).modulo(-3) == -2); + /// assert!(( 8).mod_floor( 3) == 2); + /// assert!(( 8).mod_floor(-3) == -1); + /// assert!((-8).mod_floor( 3) == 1); + /// assert!((-8).mod_floor(-3) == -2); /// - /// assert!(( 1).modulo( 2) == 1); - /// assert!(( 1).modulo(-2) == -1); - /// assert!((-1).modulo( 2) == 1); - /// assert!((-1).modulo(-2) == -1); + /// assert!(( 1).mod_floor( 2) == 1); + /// assert!(( 1).mod_floor(-2) == -1); + /// assert!((-1).mod_floor( 2) == 1); + /// assert!((-1).mod_floor(-2) == -1); /// ~~~ /// #[inline(always)] - fn modulo(&self, other: &T) -> T { + fn mod_floor(&self, other: &T) -> T { // Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_, // December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf) match *self % *other { @@ -361,21 +356,21 @@ impl Integer for T { } } - /// Calculates `div` and `modulo` simultaneously + /// Calculates `div_floor` and `mod_floor` simultaneously #[inline(always)] - fn div_mod(&self, other: &T) -> (T,T) { + fn div_mod_floor(&self, other: &T) -> (T,T) { // Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_, // December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf) - match self.quot_rem(other) { - (q, r) if (r > 0 && *other < 0) - || (r < 0 && *other > 0) => (q - 1, r + *other), - (q, r) => (q, r), + match self.div_rem(other) { + (d, r) if (r > 0 && *other < 0) + || (r < 0 && *other > 0) => (d - 1, r + *other), + (d, r) => (d, r), } } - /// Calculates `quot` (`\`) and `rem` (`%`) simultaneously + /// Calculates `div` (`\`) and `rem` (`%`) simultaneously #[inline(always)] - fn quot_rem(&self, other: &T) -> (T,T) { + fn div_rem(&self, other: &T) -> (T,T) { (*self / *other, *self % *other) } @@ -599,42 +594,42 @@ mod tests { } #[test] - fn test_quot_rem() { - fn test_nd_qr(nd: (T,T), qr: (T,T)) { + fn test_div_rem() { + fn test_nd_dr(nd: (T,T), qr: (T,T)) { let (n,d) = nd; - let separate_quot_rem = (n / d, n % d); - let combined_quot_rem = n.quot_rem(&d); + let separate_div_rem = (n / d, n % d); + let combined_div_rem = n.div_rem(&d); - assert_eq!(separate_quot_rem, qr); - assert_eq!(combined_quot_rem, qr); + assert_eq!(separate_div_rem, qr); + assert_eq!(combined_div_rem, qr); - test_division_rule(nd, separate_quot_rem); - test_division_rule(nd, combined_quot_rem); + test_division_rule(nd, separate_div_rem); + test_division_rule(nd, combined_div_rem); } - test_nd_qr(( 8, 3), ( 2, 2)); - test_nd_qr(( 8, -3), (-2, 2)); - test_nd_qr((-8, 3), (-2, -2)); - test_nd_qr((-8, -3), ( 2, -2)); + test_nd_dr(( 8, 3), ( 2, 2)); + test_nd_dr(( 8, -3), (-2, 2)); + test_nd_dr((-8, 3), (-2, -2)); + test_nd_dr((-8, -3), ( 2, -2)); - test_nd_qr(( 1, 2), ( 0, 1)); - test_nd_qr(( 1, -2), ( 0, 1)); - test_nd_qr((-1, 2), ( 0, -1)); - test_nd_qr((-1, -2), ( 0, -1)); + test_nd_dr(( 1, 2), ( 0, 1)); + test_nd_dr(( 1, -2), ( 0, 1)); + test_nd_dr((-1, 2), ( 0, -1)); + test_nd_dr((-1, -2), ( 0, -1)); } #[test] - fn test_div_mod() { + fn test_div_mod_floor() { fn test_nd_dm(nd: (T,T), dm: (T,T)) { let (n,d) = nd; - let separate_div_mod = (n.div(&d), n.modulo(&d)); - let combined_div_mod = n.div_mod(&d); + let separate_div_mod_floor = (n.div_floor(&d), n.mod_floor(&d)); + let combined_div_mod_floor = n.div_mod_floor(&d); - assert_eq!(separate_div_mod, dm); - assert_eq!(combined_div_mod, dm); + assert_eq!(separate_div_mod_floor, dm); + assert_eq!(combined_div_mod_floor, dm); - test_division_rule(nd, separate_div_mod); - test_division_rule(nd, combined_div_mod); + test_division_rule(nd, separate_div_mod_floor); + test_division_rule(nd, combined_div_mod_floor); } test_nd_dm(( 8, 3), ( 2, 2)); diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 3e43ebfef12..b8f47db7d12 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -11,13 +11,11 @@ //! An interface for numeric types use cmp::{Eq, Ord}; #[cfg(stage0)] -use ops::{Add, Sub, Mul, Neg}; -#[cfg(stage0)] -use Quot = ops::Div; +use ops::{Add, Sub, Mul, Div, Neg}; #[cfg(stage0)] use Rem = ops::Modulo; #[cfg(not(stage0))] -use ops::{Add, Sub, Mul, Quot, Rem, Neg}; +use ops::{Add, Sub, Mul, Div, Rem, Neg}; use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr}; use option::Option; use kinds::Copy; @@ -32,7 +30,7 @@ pub trait Num: Eq + Zero + One + Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> - + Quot<Self,Self> + + Div<Self,Self> + Rem<Self,Self> {} pub trait IntConvertible { @@ -76,12 +74,13 @@ pub fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T { pub trait Integer: Num + Orderable - + Quot<Self,Self> + + Div<Self,Self> + Rem<Self,Self> { - fn div(&self, other: &Self) -> Self; - fn modulo(&self, other: &Self) -> Self; - fn div_mod(&self, other: &Self) -> (Self,Self); - fn quot_rem(&self, other: &Self) -> (Self,Self); + fn div_rem(&self, other: &Self) -> (Self,Self); + + fn div_floor(&self, other: &Self) -> Self; + fn mod_floor(&self, other: &Self) -> Self; + fn div_mod_floor(&self, other: &Self) -> (Self,Self); fn gcd(&self, other: &Self) -> Self; fn lcm(&self, other: &Self) -> Self; @@ -102,7 +101,7 @@ pub trait Round { pub trait Fractional: Num + Orderable + Round - + Quot<Self,Self> { + + Div<Self,Self> { fn recip(&self) -> Self; } @@ -226,7 +225,7 @@ pub trait Primitive: Num + Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> - + Quot<Self,Self> + + Div<Self,Self> + Rem<Self,Self> { // FIXME (#5527): These should be associated constants fn bits() -> uint; @@ -371,7 +370,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<T:NumCast+One+Zero+Copy+Quot<T,T>+Mul<T,T>>( +pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>( radix: uint, pow: uint) -> T { let _0: T = Zero::zero(); let _1: T = One::one(); @@ -413,13 +412,13 @@ pub 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.div(&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.div(&two), ten / two); assert_eq!(ten.rem(&two), ten % two); } diff --git a/src/libcore/num/strconv.rs b/src/libcore/num/strconv.rs index 2f3cd92dac0..68e3b407a8b 100644 --- a/src/libcore/num/strconv.rs +++ b/src/libcore/num/strconv.rs @@ -10,15 +10,13 @@ use core::cmp::{Ord, Eq}; #[cfg(stage0)] -use ops::{Add, Sub, Mul, Neg}; -#[cfg(stage0)] -use Quot = ops::Div; +use ops::{Add, Sub, Mul, Div, Neg}; #[cfg(stage0)] use Rem = ops::Modulo; #[cfg(stage1)] #[cfg(stage2)] #[cfg(stage3)] -use ops::{Add, Sub, Mul, Quot, Rem, Neg}; +use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; use char; use str; @@ -67,7 +65,7 @@ fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool { } #[inline(always)] -fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Quot<T,T>>(num: &T) -> bool { +fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool { let _0: T = Zero::zero(); let _1: T = One::one(); @@ -180,7 +178,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<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+ - Quot<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( + Div<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 { @@ -388,7 +386,7 @@ pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+ */ #[inline(always)] pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+ - Quot<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( + Div<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, @@ -441,7 +439,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<T:NumCast+Zero+One+Eq+Ord+Copy+Quot<T,T>+ +pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+ Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+ NumStrConv>( buf: &[u8], radix: uint, negative: bool, fractional: bool, @@ -638,7 +636,7 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Quot<T,T>+ * `from_str_bytes_common()`, for details see there. */ #[inline(always)] -pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Quot<T,T>+Mul<T,T>+ +pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<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, diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 3dfdd22c42d..f6b98989545 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -31,7 +31,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 quot(x: T, y: T) -> T { x / y } +pub fn div(x: T, y: T) -> T { x / y } #[inline(always)] pub fn rem(x: T, y: T) -> T { x % y } @@ -166,16 +166,11 @@ impl Mul<T,T> for T { fn mul(&self, other: &T) -> T { *self * *other } } -#[cfg(stage0,notest)] +#[cfg(notest)] impl Div<T,T> for T { #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } -#[cfg(not(stage0),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 { @@ -197,23 +192,23 @@ impl Neg<T> for T { impl Unsigned for T {} impl Integer for T { - /// Unsigned integer division. Returns the same result as `quot` (`/`). + /// Calculates `div` (`\`) and `rem` (`%`) simultaneously #[inline(always)] - fn div(&self, other: &T) -> T { *self / *other } + fn div_rem(&self, other: &T) -> (T,T) { + (*self / *other, *self % *other) + } - /// Unsigned integer modulo operation. Returns the same result as `rem` (`%`). + /// Unsigned integer division. Returns the same result as `div` (`/`). #[inline(always)] - fn modulo(&self, other: &T) -> T { *self / *other } + fn div_floor(&self, other: &T) -> T { *self / *other } - /// Calculates `div` and `modulo` simultaneously + /// Unsigned integer modulo operation. Returns the same result as `rem` (`%`). #[inline(always)] - fn div_mod(&self, other: &T) -> (T,T) { - (*self / *other, *self % *other) - } + fn mod_floor(&self, other: &T) -> T { *self / *other } - /// Calculates `quot` (`\`) and `rem` (`%`) simultaneously + /// Calculates `div_floor` and `modulo_floor` simultaneously #[inline(always)] - fn quot_rem(&self, other: &T) -> (T,T) { + fn div_mod_floor(&self, other: &T) -> (T,T) { (*self / *other, *self % *other) } |
