Skip to content

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
boyter:masterfrom
YuriNachos:YuriNachos/w2-scc
Open

fix: use float division for COCOMO monthly wage so non-divisible avg-wage is not truncated#738
YuriNachos wants to merge 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/w2-scc

Conversation

@YuriNachos

Copy link
Copy Markdown

Summary

  • EstimateCost computed the monthly wage as float64(averageWage/12) — the division averageWage/12 is Go integer division (both operands int64), truncated to a whole number BEFORE the float64(...) cast runs. Any annual wage not evenly divisible by 12 was therefore silently under-counted. The shipped default --avg-wage 56286 has a monthly wage of 4690.5, but was truncated to 4690.
  • Fix: move the cast in front of the division → float64(averageWage) / 12. One-line change.

Root cause

// before — integer divide inside the cast:
return effortApplied * float64(averageWage/12) * overhead
// after  — cast before divide, so the division is float:
return effortApplied * float64(averageWage) / 12 * overhead

Changes

File Change
processor/cocomo.go float64(averageWage/12)float64(averageWage) / 12.
processor/cocomo_test.go TestEstimateCostManyLines expected window updated from the truncated value (~2602096) to the correct one (~2602469) — the old assertion had hardcoded the buggy output. New TestEstimateCostMonthlyWagePrecision asserts the non-truncated monthly wage for the default 56286 (4690.5), red on master'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 TestEstimateCostTestEstimateCostManyLines + TestEstimateCostMonthlyWagePrecision both pass.
  • Red-before-green: on master the new precision test fails (truncated 4690 vs 4690.5); after the one-line fix it passes. Reverting the fix re-fails it.
  • go generate — no diff (cocomo.go is not a generate-input).

I licence this contribution under the MIT licence.

…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>
@pr-insights pr-insights Bot added L/complexity Low complexity S/size Small change labels Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L/complexity Low complexity S/size Small change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant