Skip to content

Slug definition appears to be off by a few parts per billion #289

@chiphogg

Description

@chiphogg

Please include the following information in your issue:

  1. Which version of units you are using: 2.3.1, although this problem exists on all versions, including 3.x.

  2. Which compiler exhibited the problem (including compiler version): All of them: it's a wrong definition in the code.


A slug is defined as the mass accelerated by 1 ft/s^2 by a net force of one lbf. This works out to some exact number of kilograms, which we can find using the following other exact definitions:

  • Standard gravitational acceleration is exactly 9.80665 m/s^2.
  • 1 foot is exactly 0.3048 m.
  • 1 pound mass is exactly 0.45359237 kg.

When I simplify this, I get that a slug is exactly (8896443230521 / 609600000000) kg, which works out to 14.5939029372063648293963... (etc.).

However, the units library slug is defined as exactly 14.5939029 kg. This amounts to an error of a few parts per billion. The error propagates to related units, e.g., foot-pounds of torque.

I think you could fix this: the numerator and denominator both fit into a std::intmax_t for std::ratio. However, since you're using std::ratio to represent unit magnitudes, instead of a vector space representation, you'll probably be more vulnerable to overflow when defining related units.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions