Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions std/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ if (isFloatingPoint!T)
*/
this(R : T)(Complex!R z)
{
re = z.re;
im = z.im;
re = T(z.re);
im = T(z.im);
}

/// ditto
this(Rx : T, Ry : T)(Rx x, Ry y)
{
re = x;
im = y;
re = T(x);
im = T(y);
}

/// ditto
Expand All @@ -192,15 +192,15 @@ if (isFloatingPoint!T)
// this = complex
ref Complex opAssign(R : T)(Complex!R z)
{
re = z.re;
im = z.im;
re = T(z.re);
im = T(z.im);
return this;
}

// this = numeric
ref Complex opAssign(R : T)(R r)
{
re = r;
re = T(r);
im = 0;
return this;
}
Expand Down Expand Up @@ -305,15 +305,15 @@ if (isFloatingPoint!T)
{
// r = lhs
// theta = 0
ab = lhs ^^ this.re;
ar = log(lhs) * this.im;
ab = T(lhs ^^ this.re);
ar = T(log(lhs) * this.im);
}
else
{
// r = -lhs
// theta = PI
ab = (-lhs) ^^ this.re * exp(-PI * this.im);
ar = PI * this.re + log(-lhs) * this.im;
ab = T((-lhs) ^^ this.re * exp(-PI * this.im));
ar = T(PI * this.re + log(-lhs) * this.im);
}

return typeof(return)(ab * cos(ar), ab * sin(ar));
Expand Down Expand Up @@ -376,8 +376,8 @@ if (isFloatingPoint!T)
immutable ab = r^^z.re * exp(-t*z.im);
immutable ar = t*z.re + log(r)*z.im;

re = ab*cos(ar);
im = ab*sin(ar);
re = T(ab*cos(ar));
im = T(ab*sin(ar));
return this;
}

Expand Down Expand Up @@ -405,8 +405,8 @@ if (isFloatingPoint!T)
import std.math : cos, sin;
immutable ab = abs(this)^^r;
immutable ar = arg(this)*r;
re = ab*cos(ar);
im = ab*sin(ar);
re = T(ab*cos(ar));
im = T(ab*sin(ar));
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ T floorImpl(T)(const T x) @trusted pure nothrow @nogc
y.vu[pos] &= 0xffff ^ ((1 << exp) - 1);

if ((x < 0.0) && (x != y.rv))
y.rv -= 1.0;
y.rv -= 1.0f;

return y.rv;
}
Expand Down Expand Up @@ -4036,7 +4036,7 @@ float ceil(float x) @trusted pure nothrow @nogc

float y = floorImpl(x);
if (y < x)
y += 1.0;
y += 1.0f;

return y;
}
Expand Down
37 changes: 21 additions & 16 deletions std/numeric.d
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,8 @@ body
// a parabolic-interpolation step
if (fabs(p) < fabs(q * r / 2) && p > q * (a - x) && p < q * (b - x))
{
d = p / q;
u = x + d;
d = T(p / q);
u = T(x + d);
// f must not be evaluated too close to a or b
if (u - a < t2 || b - u < t2)
d = x < m ? tolerance : -tolerance;
Expand All @@ -1544,7 +1544,7 @@ body
d = c * e;
}
// f must not be evaluated too close to x
u = x + (fabs(d) >= tolerance ? d : d > 0 ? tolerance : -tolerance);
u = T(x + (fabs(d) >= tolerance ? d : d > 0 ? tolerance : -tolerance));
immutable fu = f(u);
if (isNaN(fu) || fu == -T.infinity)
{
Expand Down Expand Up @@ -1942,11 +1942,12 @@ result is greater than or equal to $(D max).
ElementType!Range entropy(Range)(Range r)
if (isInputRange!Range)
{
Unqual!(typeof(return)) result = 0.0;
alias T = Unqual!(typeof(return));
T result = 0.0;
for (;!r.empty; r.popFront)
{
if (!r.front) continue;
result -= r.front * log2(r.front);
result -= T(r.front * log2(r.front));
}
return result;
}
Expand All @@ -1956,11 +1957,12 @@ ElementType!Range entropy(Range, F)(Range r, F max)
if (isInputRange!Range &&
!is(CommonType!(ElementType!Range, F) == void))
{
Unqual!(typeof(return)) result = 0.0;
alias T = Unqual!(typeof(return));
T result = 0.0;
for (;!r.empty; r.popFront)
{
if (!r.front) continue;
result -= r.front * log2(r.front);
result -= T(r.front * log2(r.front));
if (result >= max) break;
}
return result;
Expand Down Expand Up @@ -1998,15 +2000,16 @@ if (isInputRange!(Range1) && isInputRange!(Range2))
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) assert(a.length == b.length);
Unqual!(typeof(return)) result = 0;
alias T = Unqual!(typeof(return));
T result = 0;
for (; !a.empty; a.popFront(), b.popFront())
{
immutable t1 = a.front;
if (t1 == 0) continue;
immutable t2 = b.front;
if (t2 == 0) return result.infinity;
assert(t1 > 0 && t2 > 0);
result += t1 * log2(t1 / t2);
result += T(t1 * log2(t1 / t2));
}
static if (!haveLen) assert(b.empty);
return result;
Expand Down Expand Up @@ -2047,19 +2050,20 @@ if (isInputRange!Range1 && isInputRange!Range2 &&
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) assert(a.length == b.length);
Unqual!(typeof(return)) result = 0;
alias T = Unqual!(typeof(return));
T result = 0;
for (; !a.empty; a.popFront(), b.popFront())
{
immutable t1 = a.front;
immutable t2 = b.front;
immutable avg = (t1 + t2) / 2;
if (t1 != 0)
{
result += t1 * log2(t1 / avg);
result += T(t1 * log2(t1 / avg));
}
if (t2 != 0)
{
result += t2 * log2(t2 / avg);
result += T(t2 * log2(t2 / avg));
}
}
static if (!haveLen) assert(b.empty);
Expand All @@ -2075,7 +2079,8 @@ if (isInputRange!Range1 && isInputRange!Range2 &&
{
enum bool haveLen = hasLength!(Range1) && hasLength!(Range2);
static if (haveLen) assert(a.length == b.length);
Unqual!(typeof(return)) result = 0;
alias T = Unqual!(typeof(return));
T result = 0;
limit *= 2;
for (; !a.empty; a.popFront(), b.popFront())
{
Expand All @@ -2084,11 +2089,11 @@ if (isInputRange!Range1 && isInputRange!Range2 &&
immutable avg = (t1 + t2) / 2;
if (t1 != 0)
{
result += t1 * log2(t1 / avg);
result += T(t1 * log2(t1 / avg));
}
if (t2 != 0)
{
result += t2 * log2(t2 / avg);
result += T(t2 * log2(t2 / avg));
}
if (result >= limit) break;
}
Expand Down Expand Up @@ -3034,7 +3039,7 @@ private:
else if (i == size * 3 / 4)
lastRow[i] = 1; // -sin(pi * 3 / 2) == 1
else
lastRow[i] = -sin(i * 2.0L * PI / size);
lastRow[i] = float(-sin(i * 2.0 * PI / size));
}

// Fill in all the other rows with strided versions.
Expand Down