diff --git a/base/constants.jl b/base/constants.jl index 6e29a837de84d..65ff7d2569de0 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -99,33 +99,33 @@ big(x::MathConst) = convert(BigFloat,x) ## specific mathematical constants @math_const π 3.14159265358979323846 pi -@math_const e 2.71828182845904523536 exp(big(1)) +@math_const ℯ 2.71828182845904523536 exp(big(1)) @math_const γ 0.57721566490153286061 euler @math_const catalan 0.91596559417721901505 catalan @math_const φ 1.61803398874989484820 (1+sqrt(big(5)))/2 # aliases const pi = π -const eu = e +const eu = ℯ const eulergamma = γ const golden = φ # special behaviors -# use exp for e^x or e.^x, as in -# ^(::MathConst{:e}, x::Number) = exp(x) -# .^(::MathConst{:e}, x) = exp(x) +# use exp for ℯ^x or ℯ.^x, as in +# ^(::MathConst{:ℯ}, x::Number) = exp(x) +# .^(::MathConst{:ℯ}, x) = exp(x) # but need to loop over types to prevent ambiguity with generic rules for ^(::Number, x) etc. for T in (MathConst, Rational, Integer, Number) - ^(::MathConst{:e}, x::T) = exp(x) + ^(::MathConst{:ℯ}, x::T) = exp(x) end for T in (Range, BitArray, SparseMatrixCSC, StridedArray, AbstractArray) - .^(::MathConst{:e}, x::T) = exp(x) + .^(::MathConst{:ℯ}, x::T) = exp(x) end -^(::MathConst{:e}, x::AbstractMatrix) = expm(x) +^(::MathConst{:ℯ}, x::AbstractMatrix) = expm(x) -log(::MathConst{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e) -log(::MathConst{:e}, x) = log(x) +log(::MathConst{:ℯ}) = 1 # use 1 to correctly promote expressions like log(x)/log(ℯ) +log(::MathConst{:ℯ}, x) = log(x) #Align along = for nice Array printing function alignment(x::MathConst) diff --git a/base/deprecated.jl b/base/deprecated.jl index 4b01ea608c8ee..f33958f8dcedd 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -522,3 +522,42 @@ export float32_isvalid, float64_isvalid @deprecate parseint(s,base) parse(Int, s, base) @deprecate parseint(T::Type, s) parse(T, s) @deprecate parseint(T::Type, s, base) parse(T, s, base) + +# Deprecation of e MathConst (#10612) +export e +const e = MathConst{:e}() + +e_depwarn() = depwarn("e mathematical constant is deprecated, use ℯ (\\u212F) or eu instead", :e) + +<(::MathConst{:e}, y::Rational{BigInt}) = (e_depwarn(); <(ℯ, y)) +<(x::Rational{BigInt}, ::MathConst{:e}) = (e_depwarn(); <(x, ℯ)) + +<(::MathConst{:e}, y::Rational) = (e_depwarn(); <(ℯ, y)) +<(x::Rational, ::MathConst{:e}) =(e_depwarn(); <(x, ℯ)) + +<=(x::MathConst{:e}, y::Rational) = (e_depwarn(); <=(ℯ, y)) +<=(x::Rational, y::MathConst{:e}) = (e_depwarn(); <=(x, ℯ)) + +hash(x::MathConst{:e}, h::UInt) = (e_depwarn(); hash(ℯ, h)) + +-(x::MathConst{:e}) = (e_depwarn(); -ℯ) +for op in Symbol[:+, :-, :*, :/, :^] + @eval $op(x::MathConst{:e}, y::MathConst{:e}) = (e_depwarn(); $op(ℯ, ℯ)) +end + +convert(::Type{BigFloat}, ::MathConst{:e}) = (e_depwarn(); convert(BigFloat, ℯ)) +convert(::Type{Float64}, ::MathConst{:e}) = (e_depwarn(); convert(Float64, ℯ)) +convert(::Type{Float32}, ::MathConst{:e}) = (e_depwarn(); convert(Float32, ℯ)) + +big(x::MathConst{:e}) = (e_depwarn(); big(ℯ)) + +for T in (MathConst, Rational, Integer, Number) + ^(::MathConst{:e}, x::T) = (e_depwarn(); ^(ℯ, x)) +end +for T in (Range, BitArray, SparseMatrixCSC, StridedArray, AbstractArray) + .^(::MathConst{:e}, x::T) = (e_depwarn(); .^(ℯ, x)) +end +^(::MathConst{:e}, x::AbstractMatrix) = (e_depwarn(); ^(ℯ, x)) + +log(::MathConst{:e}) = (e_depwarn(); log(ℯ)) +log(::MathConst{:e}, x) = (e_depwarn(); log(ℯ, x)) diff --git a/base/exports.jl b/base/exports.jl index f046437c1f4d7..cd6ad5dd6c965 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -184,7 +184,7 @@ export NaN32, im, π, pi, - e, eu, + ℯ, eu, γ, eulergamma, catalan, φ, golden, diff --git a/test/numbers.jl b/test/numbers.jl index 3169ae585cdc9..5c06038278cd0 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2320,7 +2320,7 @@ end @test bswap(reinterpret(Float32,0x0000c03f)) === 1.5f0 #isreal(x::Real) = true -for x in [1.23, 7, e, 4//5] #[FP, Int, MathConst, Rat] +for x in [1.23, 7, ℯ, 4//5] #[FP, Int, MathConst, Rat] @test isreal(x) == true end @@ -2335,20 +2335,20 @@ for x in [subtypes(Complex); subtypes(Real)] end #getindex(x::Number) = x -for x in [1.23, 7, e, 4//5] #[FP, Int, MathConst, Rat] +for x in [1.23, 7, ℯ, 4//5] #[FP, Int, MathConst, Rat] @test getindex(x) == x end #copysign(x::Real, y::Real) = ifelse(signbit(x)!=signbit(y), -x, x) #same sign -for x in [1.23, 7, e, 4//5] - for y in [1.23, 7, e, 4//5] +for x in [1.23, 7, ℯ, 4//5] + for y in [1.23, 7, ℯ, 4//5] @test copysign(x,y) == x end end #different sign -for x in [1.23, 7, e, 4//5] - for y in [1.23, 7, e, 4//5] +for x in [1.23, 7, ℯ, 4//5] + for y in [1.23, 7, ℯ, 4//5] @test copysign(x, -y) == -x end end @@ -2361,7 +2361,7 @@ end #in(x::Number, y::Number) = x == y @test in(3,3) == true #Int @test in(2.0,2.0) == true #FP -@test in(e,e) == true #Const +@test in(ℯ,ℯ) == true #Const @test in(4//5,4//5) == true #Rat @test in(1+2im, 1+2im) == true #Imag @test in(3, 3.0) == true #mixed