Skip to content

Commit ee26c7c

Browse files
committed
Revert rename of Div to Quot
1 parent 7a85767 commit ee26c7c

27 files changed

+199
-235
lines changed

doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,8 @@ A complete list of the built-in language items follows:
14671467
: Elements can be subtracted.
14681468
`mul`
14691469
: Elements can be multiplied.
1470-
`quot`
1471-
: Elements have a quotient operation.
1470+
`div`
1471+
: Elements have a division operation.
14721472
`rem`
14731473
: Elements have a remainder operation.
14741474
`neg`
@@ -1857,7 +1857,7 @@ The default meaning of the operators on standard types is given here.
18571857
Calls the `mul` method on the `core::ops::Mul` trait.
18581858
`/`
18591859
: Quotient.
1860-
Calls the `quot` method on the `core::ops::Quot` trait.
1860+
Calls the `div` method on the `core::ops::Div` trait.
18611861
`%`
18621862
: Remainder.
18631863
Calls the `rem` method on the `core::ops::Rem` trait.

src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use ops::{Drop};
7878
#[cfg(stage0)]
7979
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
8080
#[cfg(not(stage0))]
81-
pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not};
81+
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
8282
pub use ops::{BitAnd, BitOr, BitXor};
8383
pub use ops::{Shl, Shr, Index};
8484

src/libcore/num/f32.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn sub(x: f32, y: f32) -> f32 { return x - y; }
123123
pub fn mul(x: f32, y: f32) -> f32 { return x * y; }
124124

125125
#[inline(always)]
126-
pub fn quot(x: f32, y: f32) -> f32 { return x / y; }
126+
pub fn div(x: f32, y: f32) -> f32 { return x / y; }
127127

128128
#[inline(always)]
129129
pub fn rem(x: f32, y: f32) -> f32 { return x % y; }
@@ -279,16 +279,11 @@ impl Mul<f32,f32> for f32 {
279279
fn mul(&self, other: &f32) -> f32 { *self * *other }
280280
}
281281

282-
#[cfg(stage0,notest)]
282+
#[cfg(notest)]
283283
impl Div<f32,f32> for f32 {
284284
#[inline(always)]
285285
fn div(&self, other: &f32) -> f32 { *self / *other }
286286
}
287-
#[cfg(not(stage0),notest)]
288-
impl Quot<f32,f32> for f32 {
289-
#[inline(always)]
290-
fn quot(&self, other: &f32) -> f32 { *self / *other }
291-
}
292287

293288
#[cfg(stage0,notest)]
294289
impl Modulo<f32,f32> for f32 {

src/libcore/num/f64.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn sub(x: f64, y: f64) -> f64 { return x - y; }
149149
pub fn mul(x: f64, y: f64) -> f64 { return x * y; }
150150

151151
#[inline(always)]
152-
pub fn quot(x: f64, y: f64) -> f64 { return x / y; }
152+
pub fn div(x: f64, y: f64) -> f64 { return x / y; }
153153

154154
#[inline(always)]
155155
pub fn rem(x: f64, y: f64) -> f64 { return x % y; }
@@ -296,15 +296,10 @@ impl Sub<f64,f64> for f64 {
296296
impl Mul<f64,f64> for f64 {
297297
fn mul(&self, other: &f64) -> f64 { *self * *other }
298298
}
299-
#[cfg(stage0,notest)]
299+
#[cfg(notest)]
300300
impl Div<f64,f64> for f64 {
301301
fn div(&self, other: &f64) -> f64 { *self / *other }
302302
}
303-
#[cfg(not(stage0),notest)]
304-
impl Quot<f64,f64> for f64 {
305-
#[inline(always)]
306-
fn quot(&self, other: &f64) -> f64 { *self / *other }
307-
}
308303
#[cfg(stage0,notest)]
309304
impl Modulo<f64,f64> for f64 {
310305
fn modulo(&self, other: &f64) -> f64 { *self % *other }

src/libcore/num/float.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use libc::c_int;
2525
use num::{Zero, One, strconv};
2626
use prelude::*;
2727

28-
pub use f64::{add, sub, mul, quot, rem, lt, le, eq, ne, ge, gt};
28+
pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
2929
pub use f64::logarithm;
3030
pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor};
3131
pub use f64::{erf, erfc, exp, expm1, exp2, abs_sub};
@@ -692,16 +692,12 @@ impl Mul<float,float> for float {
692692
fn mul(&self, other: &float) -> float { *self * *other }
693693
}
694694
695-
#[cfg(stage0,notest)]
695+
#[cfg(notest)]
696696
impl Div<float,float> for float {
697697
#[inline(always)]
698698
fn div(&self, other: &float) -> float { *self / *other }
699699
}
700-
#[cfg(not(stage0),notest)]
701-
impl Quot<float,float> for float {
702-
#[inline(always)]
703-
fn quot(&self, other: &float) -> float { *self / *other }
704-
}
700+
705701
#[cfg(stage0,notest)]
706702
impl Modulo<float,float> for float {
707703
#[inline(always)]

src/libcore/num/int-template.rs

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn sub(x: T, y: T) -> T { x - y }
3030
#[inline(always)]
3131
pub fn mul(x: T, y: T) -> T { x * y }
3232
#[inline(always)]
33-
pub fn quot(x: T, y: T) -> T { x / y }
33+
pub fn div(x: T, y: T) -> T { x / y }
3434

3535
///
3636
/// Returns the remainder of y / x.
@@ -201,16 +201,11 @@ impl Mul<T,T> for T {
201201
fn mul(&self, other: &T) -> T { *self * *other }
202202
}
203203
204-
#[cfg(stage0,notest)]
204+
#[cfg(notest)]
205205
impl Div<T,T> for T {
206-
#[inline(always)]
207-
fn div(&self, other: &T) -> T { *self / *other }
208-
}
209-
#[cfg(not(stage0),notest)]
210-
impl Quot<T,T> for T {
211206
///
212-
/// Returns the integer quotient, truncated towards 0. As this behaviour reflects
213-
/// the underlying machine implementation it is more efficient than `Natural::div`.
207+
/// Integer division, truncated towards 0. As this behaviour reflects the underlying
208+
/// machine implementation it is more efficient than `Integer::div_floor`.
214209
///
215210
/// # Examples
216211
///
@@ -227,7 +222,7 @@ impl Quot<T,T> for T {
227222
/// ~~~
228223
///
229224
#[inline(always)]
230-
fn quot(&self, other: &T) -> T { *self / *other }
225+
fn div(&self, other: &T) -> T { *self / *other }
231226
}
232227
233228
#[cfg(stage0,notest)]
@@ -307,51 +302,51 @@ impl Integer for T {
307302
/// # Examples
308303
///
309304
/// ~~~
310-
/// assert!(( 8).div( 3) == 2);
311-
/// assert!(( 8).div(-3) == -3);
312-
/// assert!((-8).div( 3) == -3);
313-
/// assert!((-8).div(-3) == 2);
305+
/// assert!(( 8).div_floor( 3) == 2);
306+
/// assert!(( 8).div_floor(-3) == -3);
307+
/// assert!((-8).div_floor( 3) == -3);
308+
/// assert!((-8).div_floor(-3) == 2);
314309
///
315-
/// assert!(( 1).div( 2) == 0);
316-
/// assert!(( 1).div(-2) == -1);
317-
/// assert!((-1).div( 2) == -1);
318-
/// assert!((-1).div(-2) == 0);
310+
/// assert!(( 1).div_floor( 2) == 0);
311+
/// assert!(( 1).div_floor(-2) == -1);
312+
/// assert!((-1).div_floor( 2) == -1);
313+
/// assert!((-1).div_floor(-2) == 0);
319314
/// ~~~
320315
///
321316
#[inline(always)]
322-
fn div(&self, other: &T) -> T {
317+
fn div_floor(&self, other: &T) -> T {
323318
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
324319
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
325-
match self.quot_rem(other) {
326-
(q, r) if (r > 0 && *other < 0)
327-
|| (r < 0 && *other > 0) => q - 1,
328-
(q, _) => q,
320+
match self.div_rem(other) {
321+
(d, r) if (r > 0 && *other < 0)
322+
|| (r < 0 && *other > 0) => d - 1,
323+
(d, _) => d,
329324
}
330325
}
331326
332327
///
333328
/// Integer modulo, satisfying:
334329
///
335330
/// ~~~
336-
/// assert!(n.div(d) * d + n.modulo(d) == n)
331+
/// assert!(n.div_floor(d) * d + n.mod_floor(d) == n)
337332
/// ~~~
338333
///
339334
/// # Examples
340335
///
341336
/// ~~~
342-
/// assert!(( 8).modulo( 3) == 2);
343-
/// assert!(( 8).modulo(-3) == -1);
344-
/// assert!((-8).modulo( 3) == 1);
345-
/// assert!((-8).modulo(-3) == -2);
337+
/// assert!(( 8).mod_floor( 3) == 2);
338+
/// assert!(( 8).mod_floor(-3) == -1);
339+
/// assert!((-8).mod_floor( 3) == 1);
340+
/// assert!((-8).mod_floor(-3) == -2);
346341
///
347-
/// assert!(( 1).modulo( 2) == 1);
348-
/// assert!(( 1).modulo(-2) == -1);
349-
/// assert!((-1).modulo( 2) == 1);
350-
/// assert!((-1).modulo(-2) == -1);
342+
/// assert!(( 1).mod_floor( 2) == 1);
343+
/// assert!(( 1).mod_floor(-2) == -1);
344+
/// assert!((-1).mod_floor( 2) == 1);
345+
/// assert!((-1).mod_floor(-2) == -1);
351346
/// ~~~
352347
///
353348
#[inline(always)]
354-
fn modulo(&self, other: &T) -> T {
349+
fn mod_floor(&self, other: &T) -> T {
355350
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
356351
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
357352
match *self % *other {
@@ -361,21 +356,21 @@ impl Integer for T {
361356
}
362357
}
363358
364-
/// Calculates `div` and `modulo` simultaneously
359+
/// Calculates `div_floor` and `mod_floor` simultaneously
365360
#[inline(always)]
366-
fn div_mod(&self, other: &T) -> (T,T) {
361+
fn div_mod_floor(&self, other: &T) -> (T,T) {
367362
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
368363
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
369-
match self.quot_rem(other) {
370-
(q, r) if (r > 0 && *other < 0)
371-
|| (r < 0 && *other > 0) => (q - 1, r + *other),
372-
(q, r) => (q, r),
364+
match self.div_rem(other) {
365+
(d, r) if (r > 0 && *other < 0)
366+
|| (r < 0 && *other > 0) => (d - 1, r + *other),
367+
(d, r) => (d, r),
373368
}
374369
}
375370
376-
/// Calculates `quot` (`\`) and `rem` (`%`) simultaneously
371+
/// Calculates `div` (`\`) and `rem` (`%`) simultaneously
377372
#[inline(always)]
378-
fn quot_rem(&self, other: &T) -> (T,T) {
373+
fn div_rem(&self, other: &T) -> (T,T) {
379374
(*self / *other, *self % *other)
380375
}
381376
@@ -599,42 +594,42 @@ mod tests {
599594
}
600595
601596
#[test]
602-
fn test_quot_rem() {
603-
fn test_nd_qr(nd: (T,T), qr: (T,T)) {
597+
fn test_div_rem() {
598+
fn test_nd_dr(nd: (T,T), qr: (T,T)) {
604599
let (n,d) = nd;
605-
let separate_quot_rem = (n / d, n % d);
606-
let combined_quot_rem = n.quot_rem(&d);
600+
let separate_div_rem = (n / d, n % d);
601+
let combined_div_rem = n.div_rem(&d);
607602
608-
assert_eq!(separate_quot_rem, qr);
609-
assert_eq!(combined_quot_rem, qr);
603+
assert_eq!(separate_div_rem, qr);
604+
assert_eq!(combined_div_rem, qr);
610605
611-
test_division_rule(nd, separate_quot_rem);
612-
test_division_rule(nd, combined_quot_rem);
606+
test_division_rule(nd, separate_div_rem);
607+
test_division_rule(nd, combined_div_rem);
613608
}
614609
615-
test_nd_qr(( 8, 3), ( 2, 2));
616-
test_nd_qr(( 8, -3), (-2, 2));
617-
test_nd_qr((-8, 3), (-2, -2));
618-
test_nd_qr((-8, -3), ( 2, -2));
610+
test_nd_dr(( 8, 3), ( 2, 2));
611+
test_nd_dr(( 8, -3), (-2, 2));
612+
test_nd_dr((-8, 3), (-2, -2));
613+
test_nd_dr((-8, -3), ( 2, -2));
619614
620-
test_nd_qr(( 1, 2), ( 0, 1));
621-
test_nd_qr(( 1, -2), ( 0, 1));
622-
test_nd_qr((-1, 2), ( 0, -1));
623-
test_nd_qr((-1, -2), ( 0, -1));
615+
test_nd_dr(( 1, 2), ( 0, 1));
616+
test_nd_dr(( 1, -2), ( 0, 1));
617+
test_nd_dr((-1, 2), ( 0, -1));
618+
test_nd_dr((-1, -2), ( 0, -1));
624619
}
625620
626621
#[test]
627-
fn test_div_mod() {
622+
fn test_div_mod_floor() {
628623
fn test_nd_dm(nd: (T,T), dm: (T,T)) {
629624
let (n,d) = nd;
630-
let separate_div_mod = (n.div(&d), n.modulo(&d));
631-
let combined_div_mod = n.div_mod(&d);
625+
let separate_div_mod_floor = (n.div_floor(&d), n.mod_floor(&d));
626+
let combined_div_mod_floor = n.div_mod_floor(&d);
632627
633-
assert_eq!(separate_div_mod, dm);
634-
assert_eq!(combined_div_mod, dm);
628+
assert_eq!(separate_div_mod_floor, dm);
629+
assert_eq!(combined_div_mod_floor, dm);
635630
636-
test_division_rule(nd, separate_div_mod);
637-
test_division_rule(nd, combined_div_mod);
631+
test_division_rule(nd, separate_div_mod_floor);
632+
test_division_rule(nd, combined_div_mod_floor);
638633
}
639634
640635
test_nd_dm(( 8, 3), ( 2, 2));

0 commit comments

Comments
 (0)