From f32b08fc19161fb4ff899ba4ca5b3b5880c78845 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 30 Apr 2020 19:05:10 -0400 Subject: [PATCH] document AbstractIrrational interface (#26555) * document AbstractIrrational interface Fixes #26550. * note hash --- base/irrationals.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/irrationals.jl b/base/irrationals.jl index 4394d67169ac7..e1994048a143f 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -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