Skip to content

one(measurement) should return 1, not 1 ± 0 #134

@stevengj

Description

@stevengj

I would suggest defining:

Base.one(::Type{Measurement{T}}) where T = one(T)

which still a correct answer since it is still a multiplicative identity for a Measurement (type promotion takes care of the rest). In general, one(x) need not return the same type as x in Julia — if the caller wants the same type, they should use oneunit(x).

one(x) is commonly used to "strip the units" from a quantity, and it would provide a nice generic way to extract the underlying scalar type from a measurement. For example, this code in QuadGK.jl should work as-is for Measurement if you define one, and you should no longer need to implement specialized QuadGK methods. (Hopefully you can eliminate your QuadGK dependency completely and it will just work.)

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