From 2b5f422aafc4382a70dec793ec71e9a2c3b82110 Mon Sep 17 00:00:00 2001 From: Yuriy Skalko Date: Mon, 25 Nov 2013 17:49:38 +0200 Subject: [PATCH] Define functions for ImaginaryUnit --- base/complex.jl | 7 +++++++ test/complex.jl | 1 + 2 files changed, 8 insertions(+) diff --git a/base/complex.jl b/base/complex.jl index a1c7d90cac1f6..9fbee37e328be 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -607,3 +607,10 @@ function atanh{T<:FloatingPoint}(z::Complex{T}) complex(ξ, η) end atanh(z::Complex) = atanh(float(z)) + +for f in (:sqrt, :exp, :log, :sin, :cos, :tan, :asin, :acos, :atan, + :sinh, :cosh, :tanh, :asinh, :acosh, :atanh) + @eval begin + ($f)(x::ImaginaryUnit) = ($f)(convert(Complex, x)) + end +end diff --git a/test/complex.jl b/test/complex.jl index 6c5cc8f99a3da..c7be36b7e77d5 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -598,3 +598,4 @@ @test complex(2,2)^2 === complex(0,8) @test_throws complex(2,2)^(-2) @test complex(2.0,2.0)^(-2) === complex(0.0, -0.125) +@test sin(im) == sin(1im)