Skip to content

fix(conversions): use US gallon and exact cubic foot factors in volume_conversion - #15812

Open
Bhaveshmeghwal21 wants to merge 1 commit into
TheAlgorithms:masterfrom
Bhaveshmeghwal21:fix/volume-conversion-gallon-cubic-foot-factors
Open

Bhaveshmeghwal21 wants to merge 1 commit into
TheAlgorithms:masterfrom
Bhaveshmeghwal21:fix/volume-conversion-gallon-cubic-foot-factors

Conversation

@Bhaveshmeghwal21

@Bhaveshmeghwal21 Bhaveshmeghwal21 commented Nov 26, 2026 •

Copy link
Copy Markdown

Describe your change

  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Add an algorithm?
  • Documentation change?

volume_conversion converts through cubic meters (value * from_factor * to_factor), so each unit's from_factor * to_factor should be 1. Two entries break that:

  • gallon goes in as 0.00454 m3 (an imperial gallon) but comes out as 264.172 gallons per m3 (US gallons). volume_conversion(1, "gallon", "litre") gave 4.54, and one gallon was 19.19 cups instead of 16.
  • cubic foot used 0.028 m3. A cubic foot is 0.0283168 m3, so it was about 1% low.

The factors are now 0.00378541 (US gallon, matching 264.172) and 0.0283168. The gallon to cubic yard and cubic foot to cup doctests held the wrong outputs, so I updated them to the corrected values (3 gallons = 0.01485 cubic yards, 4 cubic feet = 478.75 cups), and added doctests for 1 gallon = 3.785 L and 1 cubic foot = 28.317 L. The doctest edits can't go in a separate PR: the old expected values came from the wrong factors, so they fail as soon as the factors are fixed.

With this change from_factor * to_factor is 1 (within 1e-5) for every unit in the table, and 1 gallon comes out as 16 cups.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant