fix handling of rounding to 12 inches in FeetInches#1656
fix handling of rounding to 12 inches in FeetInches#1656Applesauce314 wants to merge 4 commits intoangularsen:masterfrom
Conversation
|
it looks like this pipeline failure is unrelated to my change, anything i need to do? |
Code ReviewSummaryFixes an edge case where rounding inches to 12 would display as e.g. "3 ft 12 in" instead of "4 ft 0 in". The core logic is correct — overflow from rounding is caught and carried into the next foot. Bug:
|
Code ReviewOverview: Fixes a bug where rounding inches to the nearest integer could produce ✅ What's good
|
Code ReviewOverviewFixes CorrectnessThe fix is correct for both paths:
var feet = Feet;
var inches = Math.Round(Inches);
if (inches == InchesInOneFoot)
{
feet++;
inches = 0;
}Handles the case where
if (numerator == fractionDenominator) { inchTrunc++; numerator = 0; }
if (inchTrunc == InchesInOneFoot) { feet++; inchTrunc = 0; }The chain is correct: fraction carry -> inch carry -> feet carry. Missing TestsNo tests are added for the bug fix. Please add test cases for the boundary values, e.g.:
Without tests this edge case may regress. StyleMinor: missing space in SummaryThe logic is correct, but the PR needs test coverage for the fixed edge case. |
fixed using `Feet` instead of local copy `feet`
fix formatting
Code ReviewBug fix: propagate inch rounding to feet in FeetInches — this is a valid and well-understood issue (analogous to 09:60 → 10:00 in time formatting). What the fix does
Concerns
Overall the logic is correct for positive values. Please add at least one test before merging. |
PR Review: fix handling of rounding to 12 inches in FeetInchesOverview: Fixes both Positive
ConcernsNegative lengths not handled:
This was pre-existing behavior, so it's out of scope for this PR, but worth adding a note or a follow-up issue. Missing regression tests:
would make this much safer. Minor
Overall: The fix is correct for the common (positive) case. Please add test coverage before merging to prevent regression. |
updates the string outputs of
FeetInchesto propagate the rounding of inches up to feet if the inches are rounded to 12.i.e 3.9999 ft in feet inches is 3 feet 11.9988 inches.
ToStringwill round the 11.9988 to 12 and output 3 ft 12 in, which is incorrect.ToArchitecturalStringwill do the same if the denominator is is not small enough to result is a fractional part that is not rounded to 1.this PR updates these methods to propagate the rounding of these functions up to the feet part while resetting the inches to 0.
i.e.
3 ft 11.9988 inbecomes4 ft 0 ininstead of3 ft 12 in.the current behavior is unexpected for a mixed radix system, and this PR implements the expected default behavior.
(for an example of a similar situation, if rounding 09:59:50 to the nearest minute, you would get 10:00, not 09:60)
this issue had been previously discussed in #158, but does not provide a way to configure the behavior as mentioned there.