Skip to content

Commit

Permalink
document AbstractIrrational interface (#26555)
Browse files Browse the repository at this point in the history
* document AbstractIrrational interface

Fixes #26550.

* note hash
  • Loading branch information
stevengj committed Apr 30, 2020
1 parent 2f90dde commit f32b08f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
"""
AbstractIrrational <: Real
Number type representing an exact irrational value.
Number type representing an exact irrational value, which is automatically rounded to the correct precision in
arithmetic operations with other numeric quantities.
Subtypes `MyIrrational <: AbstractIrrational` should implement at least `==(::MyIrrational, ::MyIrrational)`,
`hash(x::MyIrrational, h::UInt)`, and `convert(::Type{F}, x::MyIrrational) where {F <: Union{BigFloat,Float32,Float64}}`.
If a subtype is used to represent values that may occasionally be rational (e.g. a square-root type that represents `√n`
for integers `n` will give a rational result when `n` is a perfect square), then it should also implement
`isinteger`, `iszero`, `isone`, and `==` with `Real` values (since all of these default to `false` for
`AbstractIrrational` types), as well as defining [`hash`](@ref) to equal that of the corresponding `Rational`.
"""
abstract type AbstractIrrational <: Real end

Expand Down

0 comments on commit f32b08f

Please sign in to comment.