Skip to content

Support multiplication of units #86

@thegedge

Description

@thegedge

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions