Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiplication of units #86

Open
thegedge opened this issue Apr 4, 2017 · 0 comments
Open

Support multiplication of units #86

thegedge opened this issue Apr 4, 2017 · 0 comments

Comments

@thegedge
Copy link
Contributor

thegedge commented Apr 4, 2017

We previously supported multiplication between Measurables, but specifically the inner product:

(Measured::Length(2, :cm) * Measured::Length(3, :cm)).to_s
> 6 cm

This is convenient, but not (mathematically) correct. When multiplying two measured values we should combine units from the same system, raising the exponent, and then multiplying/dividing the other units:

Measured::Length(2, :cm) * Measured::Length(3, :cm)
> 6 cm^2

Measured::Length(2, :m) * Measured::Length(0.002, :km) / Measured::Time(0.1, :seconds)
> 40 m/s

This change should not come at a performance penalty for any current use cases:

  • unit + unit
  • unit.scale(scalar)
  • unit.convert_to(:simple_unit)
  • etc
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

No branches or pull requests

1 participant