Skip to content

Commit

Permalink
std.math №3: conj for double and float
Browse files Browse the repository at this point in the history
Issue 14206 workaround
  • Loading branch information
9il committed Feb 20, 2015
1 parent 398a1e9 commit efabbd3
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions std/math.d
Expand Up @@ -533,24 +533,50 @@ 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;
}

///
@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.
Expand Down

0 comments on commit efabbd3

Please sign in to comment.