Skip to content

fix(Unit): use the exact value for the acre unit#3665

Open
spokodev wants to merge 1 commit into
josdejong:developfrom
spokodev:fix-acre-exact-value
Open

fix(Unit): use the exact value for the acre unit#3665
spokodev wants to merge 1 commit into
josdejong:developfrom
spokodev:fix-acre-exact-value

Conversation

@spokodev

Copy link
Copy Markdown

Problem

The acre unit is stored as a rounded 4046.86 m2, while the units it is defined from are stored at full precision (sqyd: 0.83612736, sqft: 0.09290304, sqmi: 2589988.110336). An acre is exactly 4840 square yards = 4046.8564224 m2, so the rounding makes conversions internally inconsistent:

math.evaluate('1 acre to sqyd') // 4840.004278773989   (expected 4840)
math.evaluate('1 acre to sqft') // 43560.0385089659    (expected 43560)
math.evaluate('1 sqmi to acre') // 639.999434212204    (expected 640)
math.evaluate('1 acre to m^2')  // 4046.86             (expected 4046.8564224)

The relative error is ~8.8e-7 — far larger than IEEE-754 noise, since 4840 * 0.83612736 is 4046.8564224 exactly.

Fix

Store the exact value, matching the precision of the units the acre is defined from:

acre: { ..., value: 4046.8564224 } // 4840 sqyd

(The international acre = 4840 international square yards, consistent with mathjs's sqyd/sqft/sqmi. The survey-based sqrd/sqch are a separate question and are left unchanged.)

Verification

  • New test in Unit.test.js asserting 1 acre == 4840 sqyd == 43560 sqft; fails before, passes after.
  • Unit.test.js: 130 passing, 0 regressions.
  • After the fix, 1 acre to sqyd / to sqft / 1 sqmi to acre are exact (relative error from 8.8e-7 to ~1e-16).

The acre was stored as a rounded `4046.86 m2`, while its defining units
`sqyd`, `sqft`, and `sqmi` are stored at full precision. An acre is defined
as exactly 4840 square yards, so it is `4046.8564224 m2`. Because of the
rounding, conversions were internally inconsistent:

  math.evaluate('1 acre to sqyd') // was 4840.004..., now exactly 4840
  math.evaluate('1 acre to sqft') // was 43560.04..., now exactly 43560

Use the exact value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant