Skip to content

Commit

Permalink
baka
Browse files Browse the repository at this point in the history
  • Loading branch information
rsk0315 committed Dec 16, 2023
1 parent 7925352 commit 191796e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions crates/math/fraction_bisect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ pub trait FractionBisect: Sized + SbInt {
if (from + to * lo).is_deeper(bound) {
let steps = bound.steps(from.into_inner(), to.into_inner());
let front = from + to * steps;

let res = if tf { (front, upper) } else { (lower, front) };
break 'outer res;
}
}

while lo.lt1(hi) {
let mid = lo.avg(hi);
let cur = pred(from + to * mid) == tf;
let tmp = from + to * mid;
let cur = pred(tmp) == tf && !tmp.is_deeper(bound);
*(if cur { &mut lo } else { &mut hi }) = mid;
}

Expand Down Expand Up @@ -105,12 +105,10 @@ macro_rules! impl_uint {
fn abs(self) -> Self { self }
fn neg(self) -> Self { self.wrapping_neg() } // not to be called
fn steps(self, from: (Self, Self), to: (Self, Self)) -> Self {
if to.0 == 0 {
(self - from.1) / to.1
} else if to.1 == 0 {
(self - from.0) / to.0
if to.1 == 0 {
Self::ZERO
} else {
((self - from.0) / to.0).min((self - from.1) / to.1)
(self - from.1) / to.1
}
}
}
Expand All @@ -132,12 +130,10 @@ macro_rules! impl_int {
fn abs(self) -> Self { self.abs() }
fn neg(self) -> Self { -self}
fn steps(self, from: (Self, Self), to: (Self, Self)) -> Self {
if to.0 == 0 {
(self - from.1) / to.1
} else if to.1 == 0 {
(self - from.0) / to.0
if to.1 == 0 {
Self::ZERO
} else {
((self - from.0) / to.0).min((self - from.1) / to.1)
(self - from.1) / to.1
}
}
}
Expand Down

0 comments on commit 191796e

Please sign in to comment.