Remove unstable feature 'zero_one' and use the impl of 'num' crate

This commit is contained in:
Eunchong Yu 2015-04-26 15:28:11 +09:00
parent b950d83454
commit d84588eb49
3 changed files with 4 additions and 41 deletions

View File

@ -8,44 +8,7 @@
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_, // Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf) // December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
use std::ops::{Add, Sub, Div, Rem}; pub use num::integer::{div_rem, div_floor, mod_floor, div_mod_floor};
use std::num::{Zero, One};
/// Same as `(a / b, a % b)`.
#[inline]
pub fn div_rem<T>(a: T, b: T) -> (T, T)
where T: Copy + Div<T,Output=T> + Rem<T,Output=T> {
(a / b, a % b)
}
/// Calculates a floored integer quotient.
#[inline]
pub fn div_floor<T>(a: T, b: T) -> T
where T: Copy + Ord + Zero + One +
Add<T,Output=T> + Sub<T,Output=T> + Div<T,Output=T> + Rem<T,Output=T> {
div_mod_floor(a, b).0
}
/// Calculates a floored modulo.
#[inline]
pub fn mod_floor<T>(a: T, b: T) -> T
where T: Copy + Ord + Zero + One +
Add<T,Output=T> + Sub<T,Output=T> + Div<T,Output=T> + Rem<T,Output=T> {
div_mod_floor(a, b).1
}
/// Calculates a floored integer quotient and modulo.
#[inline]
pub fn div_mod_floor<T>(a: T, b: T) -> (T, T)
where T: Copy + Ord + Zero + One +
Add<T,Output=T> + Sub<T,Output=T> + Div<T,Output=T> + Rem<T,Output=T> {
let zero = Zero::zero();
let one = One::one();
match (a / b, a % b) {
(d, r) if (r > zero && b < zero) || (r < zero && b > zero) => (d - one, r + b),
(d, r) => (d, r),
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -267,7 +267,7 @@ Advanced time zone handling is not yet supported (but is planned in 0.3).
#![doc(html_root_url = "https://lifthrasiir.github.io/rust-chrono/")] #![doc(html_root_url = "https://lifthrasiir.github.io/rust-chrono/")]
#![feature(std_misc, zero_one)] // lib stability features as per RFC #507 #![feature(std_misc)] // lib stability features as per RFC #507
#![cfg_attr(test, feature(test))] // ditto #![cfg_attr(test, feature(test))] // ditto
#![deny(missing_docs)] #![deny(missing_docs)]
@ -600,7 +600,7 @@ pub trait Timelike {
#[test] #[test]
fn test_readme_doomsday() { fn test_readme_doomsday() {
use std::iter::range_inclusive; use num::iter::range_inclusive;
for y in range_inclusive(naive::date::MIN.year(), naive::date::MAX.year()) { for y in range_inclusive(naive::date::MIN.year(), naive::date::MAX.year()) {
// even months // even months

View File

@ -1495,7 +1495,7 @@ mod internals {
use Weekday; use Weekday;
use super::{Of, Mdf}; use super::{Of, Mdf};
use super::{YearFlags, A, B, C, D, E, F, G, AG, BA, CB, DC, ED, FE, GF}; use super::{YearFlags, A, B, C, D, E, F, G, AG, BA, CB, DC, ED, FE, GF};
use std::iter::range_inclusive; use num::iter::range_inclusive;
use std::u32; use std::u32;
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G]; const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];