Skip to content

Commit

Permalink
Minor stylistic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Mar 16, 2024
1 parent 8417c59 commit 7354a36
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ pub(crate) fn evaluate<I: Interrupt>(
}
Expr::Equality(is_equals, a, b) => {
let lhs = evaluate(*a, scope.clone(), attrs, context, int)?;
let rhs = evaluate(*b, scope.clone(), attrs, context, int)?;
let rhs = evaluate(*b, scope, attrs, context, int)?;
Value::Bool(match lhs.compare(&rhs, int)? {
Some(cmp::Ordering::Equal) => is_equals,
Some(cmp::Ordering::Greater | cmp::Ordering::Less) | None => !is_equals,
Expand Down
2 changes: 1 addition & 1 deletion core/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) struct Date {
}

impl Date {
pub(crate) fn today(context: &mut crate::Context) -> FResult<Self> {
pub(crate) fn today(context: &crate::Context) -> FResult<Self> {
let Some(current_time_info) = &context.current_time else {
return Err(FendError::UnableToGetCurrentDate);
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn evaluate_to_value<I: Interrupt>(
let mut missing_open_parens: i32 = 0;
for token in lex {
let token = token?;
if let lexer::Token::Symbol(lexer::Symbol::CloseParens) = token {
if matches!(token, lexer::Token::Symbol(lexer::Symbol::CloseParens)) {
missing_open_parens += 1;
}
tokens.push(token);
Expand Down
2 changes: 1 addition & 1 deletion core/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ impl<'a, I: Interrupt> Iterator for Lexer<'a, '_, I> {
res,
Some(Ok(Token::Num(_) | Token::Symbol(Symbol::UnitConversion)))
);
if let Some(Ok(Token::Symbol(Symbol::Backslash))) = res {
if matches!(res, Some(Ok(Token::Symbol(Symbol::Backslash)))) {
self.after_backslash_state = 1;
} else if self.after_backslash_state == 1 {
if let Some(Ok(Token::Ident(_))) = res {
Expand Down
5 changes: 2 additions & 3 deletions core/src/num/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Complex {
let rem = rhs.clone().real.modulo(4.into(), int);
// Reduced case: (ix)^y = x^y * i^y
if self.real.is_zero() && rhs.imag.is_zero() {
if let Ok(n) = rhs.real.clone().try_as_usize(int) {
if let Ok(n) = rhs.real.try_as_usize(int) {
return self.pow_n(n, int);
}

Expand Down Expand Up @@ -380,8 +380,7 @@ impl Complex {
let sqrt = Exact::new(Self::from(1), true)
.add(exact.clone().mul(&exact, int)?.neg(), int)?
.try_and_then(|x| x.frac_pow(half.value, int))?;
i.clone()
.mul(&exact, int)?
i.mul(&exact, int)?
.add(sqrt, int)?
.try_and_then(|x| x.ln(int))
}
Expand Down
15 changes: 4 additions & 11 deletions core/src/num/continued_fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ContinuedFraction {
let mut denominator = 1.0;
for term in self.into_iter().take(MAX_ITERATIONS) {
denominator = 1.0 / (denominator + term.as_f64());
result = result * denominator + term.as_f64();
result = result.mul_add(denominator, term.as_f64());
}
result
}
Expand Down Expand Up @@ -404,17 +404,11 @@ impl Iterator for BihomographicIterator {
}
BihomographicState::Shift { right_first } => {
if right_first {
if let Ok(()) = self.shift_right() {
self.state = BihomographicState::Initial;
continue;
} else if let Ok(()) = self.shift_down() {
if self.shift_right() == Ok(()) || self.shift_down() == Ok(()) {
self.state = BihomographicState::Initial;
continue;
}
} else if let Ok(()) = self.shift_down() {
self.state = BihomographicState::Initial;
continue;
} else if let Ok(()) = self.shift_right() {
} else if self.shift_down() == Ok(()) || self.shift_right() == Ok(()) {
self.state = BihomographicState::Initial;
continue;
}
Expand Down Expand Up @@ -807,8 +801,7 @@ mod tests {
.take(1000)
.map(|b| b.try_as_usize(&Never).unwrap())
.collect::<Vec<_>>(),
Some(1)
.into_iter()
iter::once(1)
.chain([2, 1, 1, 2, 36].into_iter().cycle())
.take(1000)
.collect::<Vec<_>>(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn query_unit_internal(
short_prefixes: bool,
case_sensitive: bool,
whole_unit: bool,
context: &mut crate::Context,
context: &crate::Context,
) -> FResult<(Cow<'static, str>, Cow<'static, str>, Cow<'static, str>)> {
if !short_prefixes {
for (s, p, d) in &context.custom_units {
Expand Down
4 changes: 2 additions & 2 deletions core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ impl Value {
Ok(match self {
Self::Num(n) => {
let other = crate::ast::evaluate(other, scope.clone(), attrs, context, int)?;
if let Self::Dp = other {
if matches!(other, Self::Dp) {
let num = Self::Num(n).expect_num()?.try_as_usize(int)?;
return Ok(Self::Format(FormattingStyle::DecimalPlaces(num)));
}
if let Self::Sf = other {
if matches!(other, Self::Sf) {
let num = Self::Num(n).expect_num()?.try_as_usize(int)?;
if num == 0 {
return Err(FendError::CannotFormatWithZeroSf);
Expand Down

0 comments on commit 7354a36

Please sign in to comment.