From 3e28e64bc0b763b84e3554aba070ad23487292db Mon Sep 17 00:00:00 2001 From: Jake Bolewski Date: Wed, 1 Apr 2015 15:02:33 -0400 Subject: [PATCH] :+100: MathConst --- base/constants.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/base/constants.jl b/base/constants.jl index 6e29a837de84d5..a7d5fdfdf3b253 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -2,7 +2,12 @@ immutable MathConst{sym} <: Real end -show{sym}(io::IO, x::MathConst{sym}) = print(io, "$sym = $(string(float(x))[1:15])...") +function show{sym}(io::IO, x::MathConst{sym}) + strx = string(float(x)) + subs = strx[1:min(15,length(strx))] + dots = length(strx) >= length(subs) ? "..." : "" + print(io, "$sym = $subs", dots) +end promote_rule{s}(::Type{MathConst{s}}, ::Type{Float32}) = Float32 promote_rule{s,t}(::Type{MathConst{s}}, ::Type{MathConst{t}}) = Float64 @@ -86,7 +91,7 @@ macro math_const(sym, val, def) quote const $esym = MathConst{$qsym}() $bigconvert - Base.convert(::Type{Float64}, ::MathConst{$qsym}) = $val + Base.convert(::Type{Float64}, ::MathConst{$qsym}) = $(Float64(val)) Base.convert(::Type{Float32}, ::MathConst{$qsym}) = $(Float32(val)) @assert isa(big($esym), BigFloat) @assert Float64($esym) == Float64(big($esym)) @@ -98,6 +103,7 @@ big(x::MathConst) = convert(BigFloat,x) ## specific mathematical constants +@math_const 💯 100 BigFloat(100) @math_const π 3.14159265358979323846 pi @math_const e 2.71828182845904523536 exp(big(1)) @math_const γ 0.57721566490153286061 euler