Fractions icon indicating copy to clipboard operation
Fractions copied to clipboard

Implemened the `INumber<Fraction>` interface (and more..)

Open lipchev opened this issue 7 months ago • 1 comments

@danm-de Sorry, I didn't realize what branch I was on, and pushed my commit to the branch of this PR.. I'll update the title and description, but if you prefer- I can split them later. Anyway, there aren't any stoppers for me here- the same fix can be applied on my side, until this is merged, so take your time.

Implementation of the INumber<Fraction> interface

  • introduced the ToDecimalSaturating method which saturates the output value to the decimal range [MinValue, MaxValue]
  • improved the accuracy (and performance) of the checked ToDecimal() when the terms are beyond the decimal range
  • fixed the possible loss of precision of the ToDouble() method when one of the terms is exceeding the range of the double (fixes #82 )
  • updated the tests and added some extreme values the ConvertToNumberBenchmark (no change among the previously tested values)

Fraction.Round: Adding a Fraction.Round overload with the "normalize" parameter:

  • when set to true- it ensures that the result is normalized (which wasn't always the case before)
  • when set to false- it maintains the decimal denominator (and skipping the GCD reduction)
  • the DecimalNotationFormatter now uses the non-normalized version (which should in theory be more performant)
  • added the required tests in Method_Round
  • updated the DecimalNotationBenchmarkResults (not much of a difference as shown by the benchmarks in the next comment)

lipchev avatar Jul 04 '24 19:07 lipchev