fix: use float division for COCOMO monthly wage so non-divisible avg-wage is not truncated - #738
Open
YuriNachos wants to merge 1 commit into
Open
fix: use float division for COCOMO monthly wage so non-divisible avg-wage is not truncated#738YuriNachos wants to merge 1 commit into
YuriNachos wants to merge 1 commit into
Conversation
…wage is not truncated EstimateCost computed the monthly wage as float64(averageWage/12), which is Go integer division truncated to a whole number BEFORE the float conversion runs. Move the cast in front of the division to float64(averageWage) / 12 so that an annual wage not evenly divisible by 12 (including the shipped default --avg-wage 56286, whose monthly wage is 4690.5, not 4690) is no longer silently under-counted on every cost line. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EstimateCostcomputed the monthly wage asfloat64(averageWage/12)— the divisionaverageWage/12is Go integer division (both operandsint64), truncated to a whole number BEFORE thefloat64(...)cast runs. Any annual wage not evenly divisible by 12 was therefore silently under-counted. The shipped default--avg-wage 56286has a monthly wage of 4690.5, but was truncated to 4690.float64(averageWage) / 12. One-line change.Root cause
Changes
processor/cocomo.gofloat64(averageWage/12)→float64(averageWage) / 12.processor/cocomo_test.goTestEstimateCostManyLinesexpected window updated from the truncated value (~2602096) to the correct one (~2602469) — the old assertion had hardcoded the buggy output. NewTestEstimateCostMonthlyWagePrecisionasserts the non-truncated monthly wage for the default 56286 (4690.5), red onmaster's truncated code and green after the fix.Different file and different concern from the open F# PR #737 (languages.json); no conflict with any open PR.
Validation
go test ./processor/ -run TestEstimateCost—TestEstimateCostManyLines+TestEstimateCostMonthlyWagePrecisionboth pass.masterthe new precision test fails (truncated4690vs4690.5); after the one-line fix it passes. Reverting the fix re-fails it.go generate— no diff (cocomo.gois not a generate-input).I licence this contribution under the MIT licence.