Skip to content

Commit

Permalink
Merge pull request #2637 from 9il/fptemp
Browse files Browse the repository at this point in the history
remove FPTemporary usage
  • Loading branch information
MartinNowak committed Nov 6, 2014
2 parents 3bb4bb2 + 9b20fb0 commit 5f9b77a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
38 changes: 18 additions & 20 deletions std/complex.d
Expand Up @@ -261,21 +261,19 @@ struct Complex(T) if (isFloatingPoint!T)
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(R r) const
if (op == "/" && isNumeric!R)
{
typeof(return) w;
alias Tmp = FPTemporary!(typeof(w.re));

typeof(return) w = void;
if (fabs(re) < fabs(im))
{
Tmp ratio = re/im;
Tmp rdivd = r/(re*ratio + im);
immutable ratio = re/im;
immutable rdivd = r/(re*ratio + im);

w.re = rdivd*ratio;
w.im = -rdivd;
}
else
{
Tmp ratio = im/re;
Tmp rdivd = r/(re + im*ratio);
immutable ratio = im/re;
immutable rdivd = r/(re + im*ratio);

w.re = rdivd;
w.im = -rdivd*ratio;
Expand All @@ -288,7 +286,7 @@ struct Complex(T) if (isFloatingPoint!T)
Complex!(CommonType!(T, R)) opBinaryRight(string op, R)(R lhs) const
if (op == "^^" && isNumeric!R)
{
FPTemporary!(CommonType!(T, R)) ab = void, ar = void;
Unqual!(CommonType!(T, R)) ab = void, ar = void;

if (lhs >= 0)
{
Expand Down Expand Up @@ -335,19 +333,19 @@ struct Complex(T) if (isFloatingPoint!T)
{
if (fabs(z.re) < fabs(z.im))
{
FPTemporary!T ratio = z.re/z.im;
FPTemporary!T denom = z.re*ratio + z.im;
immutable ratio = z.re/z.im;
immutable denom = z.re*ratio + z.im;

auto temp = (re*ratio + im)/denom;
immutable temp = (re*ratio + im)/denom;
im = (im*ratio - re)/denom;
re = temp;
}
else
{
FPTemporary!T ratio = z.im/z.re;
FPTemporary!T denom = z.re + z.im*ratio;
immutable ratio = z.im/z.re;
immutable denom = z.re + z.im*ratio;

auto temp = (re + im*ratio)/denom;
immutable temp = (re + im*ratio)/denom;
im = (im - re*ratio)/denom;
re = temp;
}
Expand All @@ -358,10 +356,10 @@ struct Complex(T) if (isFloatingPoint!T)
ref Complex opOpAssign(string op, C)(C z)
if (op == "^^" && is(C R == Complex!R))
{
FPTemporary!T r = abs(this);
FPTemporary!T t = arg(this);
FPTemporary!T ab = r^^z.re * exp(-t*z.im);
FPTemporary!T ar = t*z.re + log(r)*z.im;
immutable r = abs(this);
immutable t = arg(this);
immutable ab = r^^z.re * exp(-t*z.im);
immutable ar = t*z.re + log(r)*z.im;

re = ab*std.math.cos(ar);
im = ab*std.math.sin(ar);
Expand Down Expand Up @@ -389,8 +387,8 @@ struct Complex(T) if (isFloatingPoint!T)
ref Complex opOpAssign(string op, R)(R r)
if (op == "^^" && isFloatingPoint!R)
{
FPTemporary!T ab = abs(this)^^r;
FPTemporary!T ar = arg(this)*r;
immutable ab = abs(this)^^r;
immutable ar = arg(this)*r;
re = ab*std.math.cos(ar);
im = ab*std.math.sin(ar);
return this;
Expand Down
8 changes: 4 additions & 4 deletions std/numeric.d
Expand Up @@ -1504,7 +1504,7 @@ cosineSimilarity(Range1, Range2)(Range1 a, Range2 b)
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) enforce(a.length == b.length);
FPTemporary!(typeof(return)) norma = 0, normb = 0, dotprod = 0;
Unqual!(typeof(return)) norma = 0, normb = 0, dotprod = 0;
for (; !a.empty; a.popFront(), b.popFront())
{
immutable t1 = a.front, t2 = b.front;
Expand Down Expand Up @@ -1689,7 +1689,7 @@ kullbackLeiblerDivergence(Range1, Range2)(Range1 a, Range2 b)
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) enforce(a.length == b.length);
FPTemporary!(typeof(return)) result = 0;
Unqual!(typeof(return)) result = 0;
for (; !a.empty; a.popFront(), b.popFront())
{
immutable t1 = a.front;
Expand Down Expand Up @@ -1734,7 +1734,7 @@ jensenShannonDivergence(Range1, Range2)(Range1 a, Range2 b)
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) enforce(a.length == b.length);
FPTemporary!(typeof(return)) result = 0;
Unqual!(typeof(return)) result = 0;
for (; !a.empty; a.popFront(), b.popFront())
{
immutable t1 = a.front;
Expand Down Expand Up @@ -1762,7 +1762,7 @@ jensenShannonDivergence(Range1, Range2, F)(Range1 a, Range2 b, F limit)
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) enforce(a.length == b.length);
FPTemporary!(typeof(return)) result = 0;
Unqual!(typeof(return)) result = 0;
limit *= 2;
for (; !a.empty; a.popFront(), b.popFront())
{
Expand Down

0 comments on commit 5f9b77a

Please sign in to comment.