Skip to content

Dynamic prefix selection #163

@dmcclean

Description

@dmcclean

I'd like to be able to display a Length Double by automatically selecting an appropriate metric prefix for meter based on the value of the Length Double rather than requiring a static selection of prefix.

As far as I can tell, we don't have support for this. Now that we have reified Prefixes, a list of siPrefixes, and the applyPrefix function (https://github.com/bjornbm/dimensional/blob/master/src/Numeric/Units/Dimensional/SIUnits.hs#L112-L116) we are close, we just need a function to select the correct prefix.

Proposed interface: (the Floating context being required to access logBase and RealFrac being required for truncate)

withAppropriatePrefix :: (Floating a, RealFrac a) => Unit 'Metric d a -> Quantity d a -> Unit 'NonMetric d a

We could possibly also expose:

appropriatePrefix :: (Floating a, RealFrac a) => Unit 'Metric d a -> Quantity d a -> Prefix

where

withAppropriatePrefix u q = applyPrefix (appropriatePrefix u q) u

Are there any reasons why this is undesirable? Are these names any good?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions