-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for NaN and Infinity #48
Conversation
- NaN represented by {0/0} - PositiveInfinity represented by {1/0} - NegativeInfinity represented by {-1/0} - Zero is now represented by {0/1} updating the tests and the benchmark results
There's a lot to review, I'm sorry- I didn't mean to change every single file but there were a lot of case to check for especially when it comes to the non-normalized fractions. I initially didn't consider having them supported for the positive/negative infinity, but as i reached the I've left (myself) a few While updating/testing the code, I also noticed that there isn't a consistent rule regarding the |
Thanks for the pull-request. Unfortunately, due to time constraints, I need a little longer for the code review this time (a few days). I still have a quick question: Is the following condition always met? Fraction.Zero == default(Fraction) |
Yes, that should evaluate as |
…(%) function - removed the GCD checking in the CompareTo (up to 2x peformaince gain) - refactored the Add/Multiply/Divide/Pow operations (another ~20% improvements on the BasicMathBenchmarks and up to 35% on the PowerMathBenchmarks) - adding more edge-case values to the benchmarks (this time actually using Pow(10, 37) instead of 10^37...)
I went over these in my last commit, and added (after substantial amount of benchmarking) the required edge-case-testing in order to minimize the number of BigInteger allocations (most often due to large multiplications).
It takes a lot more ifs and elses, but even operations such as Multiply/Divide/Pow can benefit from not doing two multiplications (when one is expected to return 0):
Note that these improvements could be applied as "non-breaking-optimizations", if we're committed on having a final/stable release of the v7... We're talking more than 20%-30% improvements on most benchmarks.. |
Since the changes are very extensive, I have integrated your GIT branch under https://github.com/danm-de/Fractions/tree/lipchev-support-nan-and-infnity I will apply my changes directly there, rather than using GITHUB's comment function. Reason: many changes have an impact on many (sub)functions and unit tests. I'm currently trying your suggestion regarding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've finished the code review and have published my suggested changes directly to the following branch:
https://github.com/danm-de/Fractions/tree/lipchev-support-nan-and-infnity
It would be nice if you could take another look.
The main changes are:
- Auto-Properties for the win (backing fields removed if possible)
- Denominator is now nullable
- Correction of the ToString(..) method
Oh, I may introduced a problem with TryParse. |
As discussed in #26
FractionState.Unknown
)I ended up not changing the
FractionState
enum, instead it is being check for when returning the defaultDenominator
Breaking changes:
Fraction.Zero.Denominator
now returns1
Denominator
- functions such asToInt64()
orToDecimal()
would throw aDivideByZeroException
Fraction.NaN.ToString("n")
would also throw aDivideByZeroException
"0/-10"
as a non-normalizedZero
, and then have itToString()
back to it's original value"0/-10"