Skip to content

Base.@irrational should be warned to not be used outside Base and should maybe be redesigned #46531

@KristofferC

Description

@KristofferC

Base.@irrational creates types of Irrational{:sym}. This means that there is no way to namespace new irrational values, they all share the same symbol slot in the Irrational type parameter.

This is a problem for packages that try to define new irrational numbers. If two packages define numbers with the same name but different values, it is undefined what value will actually be used which can be a quite severe bug.

I think we should state in the docstring that packages should not use this macro since it is currently so brittle.

It is also probably a good idea to think about a design that does not have this issue. Something with an abstract super type AbstractIrrational and having the macro create a new type that is a subtype of that seems like it should be workable:

abstract type AbstractIrrational end

struct Euler <: AbstractIrrational end
const euler = Euler()
@eval BigFloat(::Euler) = $(exp(big(1)))
Float64(::Euler) = 2.71828182845904523536

and then have methods defined on AbstractIrrational.

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