Skip to content

Request: Define Scalar Units in Terms of Other Units #8

@CrownedPhoenix

Description

@CrownedPhoenix

Situation: I want to define "quart".

This is currently how I have to do it.

public static let quart = try! Units.Unit.register(
    name: "quart",
    symbol: "qt",
    dimension: [.Length: 3],
    coefficient: 0.0009463529 // This is the conversion to kiloliters
)

Problem:

  • It was not obvious to me that the coefficient should be the scalar conversion to kiloliters. I had to dig around the list of defined units to find the [.Length: 3] one with coefficient: 1.
  • Then I had to Google "quart to kiloliter" which gave me this long coefficient that I'm not sure how accurate it is. But I already know that a quart is 1/4 gallon (exactly).

Desired Solution:

extension Unit {
  public static let quart = try! Units.Unit.register(
      name: "quart",
      symbol: "qt",
      derivation: 0.25 * .gallon
    )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions