add a round_ties_even for Ratio<T>#141
Conversation
02bec5e to
da728d6
Compare
da728d6 to
797bd6e
Compare
|
Something that struck me was how complicated the current |
|
i'll have to think about that with a pen and paper tomorrow (after getting some sleep) to see if that works or has the potential of overflowing, but i am not actually sure, if that is even a really worthwhile optimization. if you give in a ratio of -5/2, you will run into two other comparisons (at the top at the i did notice an unnecessary call to |
797bd6e to
f0c94f3
Compare
|
The basic idea is if All that said, I get your point about losing clarity in the code. My method also might not be valid if |
i am working on a rust scheme interpreter, and the scheme
(round x)procedure is specified to "round[...] to even when x is halfway between two integers", and is supposed to work on all number types available in scheme, which includes rationals.since that interpreter uses this library, i figured i'd try to get my implementation into upstream.
the actual implementation i did seems "too easy", i just
cmpit with aRatio::new(one, two)and then do the same withGreaterandLesslike theroundfn does it. if it isEquali first round towards zero (viatrunc, like in theLesspath) see if itis_even, and then round away from zero (by adding/subtracting 1, like in theGreaterpath) if not.