commit bed919b5c3d5ec21391a1b53fdc82ec628a1aea7
parent 6d9f4ad39dc96730d1b474a9e45e9610c3b87101
Author: Zack Newman <zack@philomathiclife.com>
Date: Fri, 14 Apr 2023 16:29:25 -0600
slight improvement in readme
Diffstat:
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -1,7 +1,7 @@
# calc_rational
calc_rational consists of a binary crate `calc` and a library crate
-`calc_lib`. `calc` is a CLI calculator for basic rational number arithmetic
+[`calc_lib`](https://docs.rs/calc_rational/latest/calc_lib). `calc` is a CLI calculator for basic rational number arithmetic
using standard operator precedence and associativity. Additionally, it
stores the previous eight evaluated expressions as well as provides a
way to display previous results in decimal form. Internally, it is
diff --git a/src/lib.rs b/src/lib.rs
@@ -620,6 +620,9 @@ impl<'input, 'cache, 'exp> Evaluator<'input, 'cache, 'exp> {
)]
fn get_rational(&mut self) -> Result<Option<Ratio<BigInt>>, E> {
#[inline]
+ // ControlFlow makes more sense to use in try_fold; however due to a lack
+ // of a map_or_else function, it is easier to simply return a Result with
+ // Err taking the role of ControlFlow::Break.
/// Used to parse a sequence of digits into an unsigned integer.
fn to_biguint(v: &[u8]) -> (BigUint, usize) {
v.into_iter()
@@ -688,7 +691,7 @@ mod tests {
assert!(Evaluator::new(b"0", &mut Cache::new(), &mut Vec::new()).get_rational().unwrap().unwrap() == Ratio::from_integer(BigInt::from_biguint(Sign::NoSign, BigUint::new(Vec::new()))));
// Leading 0s and trailing 0s are fine.
assert!(Evaluator::new(b"0000.00000", &mut Cache::new(), &mut Vec::new()).get_rational().unwrap().unwrap() == Ratio::from_integer(BigInt::from_biguint(Sign::NoSign, BigUint::new(Vec::new()))));
- // Parsing stops at first non-(digt/period).
+ // Parsing stops at first non-(digit/period).
assert!(Evaluator::new(b"1 0", &mut Cache::new(), &mut Vec::new()).get_rational().unwrap().unwrap() == Ratio::from_integer(BigInt::from_biguint(Sign::Plus, BigUint::new(vec![1]))));
let int = b"3397450981271938475135134759823759835414";
let frac = b"913759810573549872354897210539127530981570";