From efabbd365e4b46337135240f18ad96fd6d78c921 Mon Sep 17 00:00:00 2001 From: Ilya Yaroshenko Date: Fri, 20 Feb 2015 12:42:10 +0300 Subject: [PATCH] =?UTF-8?q?std.math=20=E2=84=963:=20conj=20for=20double=20?= =?UTF-8?q?and=20float?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue 14206 workaround --- std/math.d | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/std/math.d b/std/math.d index f37ae3abd81..e72504fad05 100644 --- a/std/math.d +++ b/std/math.d @@ -533,13 +533,22 @@ real abs(Num)(Num y) @safe pure nothrow @nogc * Note that z * conj(z) = $(POWER z.re, 2) - $(POWER z.im, 2) * is always a real number */ -creal conj(creal z) @safe pure nothrow @nogc +auto conj(Num)(Num z) @safe pure nothrow @nogc + if (is(Num* : const(cfloat*)) || is(Num* : const(cdouble*)) + || is(Num* : const(creal*))) { - return z.re - z.im*1i; + //FIXME + //Issue 14206 + static if(is(Num* : const(cdouble*))) + return cast(cdouble) conj(cast(creal)z); + else + return z.re - z.im*1fi; } /** ditto */ -ireal conj(ireal y) @safe pure nothrow @nogc +auto conj(Num)(Num y) @safe pure nothrow @nogc + if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*)) + || is(Num* : const(ireal*))) { return -y; } @@ -547,10 +556,27 @@ ireal conj(ireal y) @safe pure nothrow @nogc /// @safe pure nothrow @nogc unittest { - assert(conj(7 + 3i) == 7-3i); + creal c = 7 + 3Li; + assert(conj(c) == 7-3Li); ireal z = -3.2Li; assert(conj(z) == -z); } +//Issue 14206 +@safe pure nothrow @nogc unittest +{ + cdouble c = 7 + 3i; + assert(conj(c) == 7-3i); + idouble z = -3.2i; + assert(conj(z) == -z); +} +//Issue 14206 +@safe pure nothrow @nogc unittest +{ + cfloat c = 7f + 3fi; + assert(conj(c) == 7f-3fi); + ifloat z = -3.2fi; + assert(conj(z) == -z); +} /*********************************** * Returns cosine of x. x is in radians.