printfn / fend

Arbitrary-precision unit-aware calculator
https://printfn.github.io/fend
MIT License
587 stars 50 forks source link

Implement `floor`, `ceil` and `round` #269

Closed frectonz closed 4 months ago

frectonz commented 4 months ago

Closes #155

I am not sure if converting BigRats into f64s and then doing the operations on them is the right way to implement this but this is what i was able to come up with. I am happy to modify the code based on any suggestions on how to do this better.

pub(crate) fn floor<I: Interrupt>(self, int: &I) -> FResult<Self> {
  let float = self.into_f64(int)?.floor();
  Self::from_f64(float, int)
}

pub(crate) fn ceil<I: Interrupt>(self, int: &I) -> FResult<Self> {
  let float = self.into_f64(int)?.ceil();
  Self::from_f64(float, int)
}

pub(crate) fn round<I: Interrupt>(self, int: &I) -> FResult<Self> {
  let float = self.into_f64(int)?.round();
  Self::from_f64(float, int)
}
codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (fb02762) 83.20% compared to head (eda5977) 83.30%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #269 +/- ## ========================================== + Coverage 83.20% 83.30% +0.10% ========================================== Files 52 52 Lines 14532 14623 +91 ========================================== + Hits 12091 12182 +91 Misses 2441 2441 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

printfn commented 4 months ago

Looks good, thanks!