Skip to content

Arithmetic with affine units results in rational when integer would suffice #757

@sostock

Description

@sostock

When adding a temperature difference in K to a temperature in °C, one often wants to have the result in °C as well. ContextUnits can be used to achieve this.

julia> x = 5 * ContextUnits(°C, °C)
5 °C

julia> x + 3K
8//1 °C

However, the result has numerical type Rational{Int} even though Int would be just fine. The reason for this is that the + method in this case converts both quantities to K to add them before converting the result back to °C.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affineaffine quantities like °C, °F, …

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions