Skip to content

Commit 131ac75

Browse files
authored
Remove unreachable remainder conversion fallbacks (#173)
1 parent aa9f7d3 commit 131ac75

1 file changed

Lines changed: 30 additions & 46 deletions

File tree

src/number.rs

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -316,53 +316,37 @@ impl Number {
316316

317317
Ok(Self::Approx(remainder))
318318
}
319-
(Self::Exact(lhs), rhs_number @ Self::Approx(rhs)) if rhs.is_finite() => {
320-
if let Some(rhs) = rhs.to_rational() {
321-
let remainder = (lhs / &rhs).complete().rem_floor() * &rhs;
322-
323-
Ok(Self::Approx(
324-
Float::with_val_round(
325-
config.precision(),
326-
remainder,
327-
config.rounding_mode,
328-
)
329-
.0,
330-
))
331-
} else {
332-
Ok(Self::Approx(
333-
Float::with_val_round(
334-
config.precision(),
335-
&self.to_float(config) % &rhs_number.to_float(config),
336-
config.rounding_mode,
337-
)
338-
.0,
339-
))
340-
}
319+
(Self::Exact(lhs), Self::Approx(rhs)) if rhs.is_finite() => {
320+
let Some(rhs) = rhs.to_rational() else {
321+
unreachable!();
322+
};
323+
324+
let remainder = (lhs / &rhs).complete().rem_floor() * &rhs;
325+
326+
Ok(Self::Approx(
327+
Float::with_val_round(
328+
config.precision(),
329+
remainder,
330+
config.rounding_mode,
331+
)
332+
.0,
333+
))
341334
}
342-
(lhs_number @ Self::Approx(lhs), rhs_number @ Self::Exact(rhs))
343-
if lhs.is_finite() =>
344-
{
345-
if let Some(lhs) = lhs.to_rational() {
346-
let remainder = (&lhs / rhs).complete().rem_floor() * rhs;
347-
348-
Ok(Self::Approx(
349-
Float::with_val_round(
350-
config.precision(),
351-
remainder,
352-
config.rounding_mode,
353-
)
354-
.0,
355-
))
356-
} else {
357-
Ok(Self::Approx(
358-
Float::with_val_round(
359-
config.precision(),
360-
&lhs_number.to_float(config) % &rhs_number.to_float(config),
361-
config.rounding_mode,
362-
)
363-
.0,
364-
))
365-
}
335+
(Self::Approx(lhs), Self::Exact(rhs)) if lhs.is_finite() => {
336+
let Some(lhs) = lhs.to_rational() else {
337+
unreachable!();
338+
};
339+
340+
let remainder = (&lhs / rhs).complete().rem_floor() * rhs;
341+
342+
Ok(Self::Approx(
343+
Float::with_val_round(
344+
config.precision(),
345+
remainder,
346+
config.rounding_mode,
347+
)
348+
.0,
349+
))
366350
}
367351
_ => Ok(Self::Approx(
368352
Float::with_val_round(

0 commit comments

Comments
 (0)