Skip to content

Comparisons with Inf fail #455

@JeffFessler

Description

@JeffFessler

This comparison fails:

1u"m" < Inf
ERROR: DimensionError: 1.0 m and Inf are not dimensionally compatible.

where I think most users would expect to be true because ±Inf should not need to have units.

Now x = 1u"m"; x > 0 also fails but here we have the acceptable alternative x > zero(x).
But there (apparently) is no analog like infinity(x) so we are stuck with Inf.

These are the key lines:
https://github.com/PainterQubits/Unitful.jl/blob/1e78e6b036144d70039b536de747dc1e83355997/src/quantities.jl#L265
https://github.com/PainterQubits/Unitful.jl/blob/1e78e6b036144d70039b536de747dc1e83355997/src/quantities.jl#L274

That last line could check for ±Inf instead of always throwing an error. The performance hit would be small because that line only gets used in the error condition. Would a PR be welcome?

I search all issue for Inf and found nothing and found just 2 issues that concern isless: #399 #30

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