| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
int() truncates toward zero, so int(-1.3) is -1 and (-1.3) - (-1) is -0.3, which Fraction turns into -3/10. Both the whole-number part and the numerator end up signed and the output reads as "-1 -3/10". The minus sign already rides on the whole-number part; absorb it from the numerator so the result is the conventional "-1 3/10". Added a few negative cases to test_fractional. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #320 +/- ##
=======================================
Coverage 99.55% 99.55%
=======================================
Files 12 12
Lines 898 900 +2
=======================================
+ Hits 894 896 +2
Misses 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry.
|
Sorry, something went wrong.
|
Thank you! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
`fractional(-1.3)` currently returns `'-1 -3/10'`. Same shape for any negative number whose absolute value is at least 1: `fractional(-2.5)` returns `'-2 -1/2'`, etc.
`int()` truncates toward zero, so `int(-1.3)` is `-1` and `-1.3 - (-1)` is `-0.3`, which `Fraction` keeps as `-3/10`. Both the whole-number part and the numerator end up signed and the format string prints them both verbatim.
The minus sign already rides on the whole-number part, so absorb it from the numerator with `abs()`. The result is the conventional mixed-fraction form `'-1 3/10'` (= -1.3).
Added negative-input cases to `test_fractional`.