Skip to content

Commit

Permalink
promote(::MathConst, ::Rational) => Rational.
Browse files Browse the repository at this point in the history
This gives the exact rational value of the float approximation,
which is probably not the best possible rational approximaion of
constants like pi or e, but this is a decent first cut.
  • Loading branch information
StefanKarpinski committed Jun 13, 2013
1 parent 4625b90 commit 24dbefc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ immutable MathConst{sym} <: Real end

show{sym}(io::IO, x::MathConst{sym}) = print(io, "$sym = $(string(float(x))[1:15])...")

promote_rule{s}(::Type{MathConst{s}}, ::Type) = Float64
promote_rule{s,T<:Real}(::Type{MathConst{s}}, ::Type{T}) = Float64
promote_rule{s,T<:Rational}(::Type{MathConst{s}}, ::Type{T}) = T
promote_rule{s}(::Type{MathConst{s}}, ::Type{Float32}) = Float32
promote_rule{s}(::Type{MathConst{s}}, ::Type{BigInt}) = BigFloat
promote_rule{s}(::Type{MathConst{s}}, ::Type{BigFloat}) = BigFloat
Expand Down

0 comments on commit 24dbefc

Please sign in to comment.