Remove unstable feature 'zero_one' and use the impl of 'num' crate
This commit is contained in:
parent
b950d83454
commit
d84588eb49
39
src/div.rs
39
src/div.rs
|
@ -8,44 +8,7 @@
|
|||
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
||||
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
|
||||
|
||||
use std::ops::{Add, Sub, Div, Rem};
|
||||
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),
|
||||
}
|
||||
}
|
||||
pub use num::integer::{div_rem, div_floor, mod_floor, div_mod_floor};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -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/")]
|
||||
|
||||
#![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
|
||||
#![deny(missing_docs)]
|
||||
|
||||
|
@ -600,7 +600,7 @@ pub trait Timelike {
|
|||
|
||||
#[test]
|
||||
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()) {
|
||||
// even months
|
||||
|
|
|
@ -1495,7 +1495,7 @@ mod internals {
|
|||
use Weekday;
|
||||
use super::{Of, Mdf};
|
||||
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;
|
||||
|
||||
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];
|
||||
|
|
Loading…
Reference in New Issue