Skip to content

Quantities should be <: Real? #680

@aplavin

Description

@aplavin

Currently, Unitful quantities are <: Number but not <: Real. This hinders composability with other libraries.

Just a few examples for methods that accept Reals and don't work with units - but actually should and totally make sense:

  • Base.searchsorted(::AbstractRange{<:Real}, ::Real) does division instead of performing binary search - so, it's faster than AbstractArray fallback
  • StatsBase.weights require AbstractVector{<:Real}

Surely there are much more.
Note that these methods are correctly restricted to reals: they don't make sense for complex numbers.

Why not make Quantity <: Real, and use Complex{Quantity} for complex unitful values?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions