Polynomial long division: Difference between revisions
Content added Content deleted
No edit summary |
(Updated D entry) |
||
Line 690: | Line 690: | ||
Tuple!(double[], double[]) polyDiv(in double[] inN, in double[] inD) |
Tuple!(double[], double[]) polyDiv(in double[] inN, in double[] inD) |
||
pure |
nothrow pure @safe { |
||
// Code smell: a function that does two things. |
// Code smell: a function that does two things. |
||
static int trimAndDegree(T)(ref T[] poly) nothrow pure { |
static int trimAndDegree(T)(ref T[] poly) nothrow pure @safe @nogc { |
||
poly = poly.retro.find!q{ a != b }(0.0).retro; |
poly = poly.retro.find!q{ a != b }(0.0).retro; |
||
return poly.length.signed - 1; |
return poly.length.signed - 1; |
||
} |
} |
||
auto N = inN.dup; |
|||
const(double)[] D = inD; |
const(double)[] D = inD; |
||
const dD = trimAndDegree(D); |
const dD = trimAndDegree(D); |
||
Line 719: | Line 719: | ||
int trimAndDegree1(T)(ref T[] poly) nothrow pure { |
int trimAndDegree1(T)(ref T[] poly) nothrow pure @safe @nogc { |
||
poly.length -= poly.retro.countUntil!q{ a != 0 }; |
poly.length -= poly.retro.countUntil!q{ a != 0 }; |
||
return poly.length.signed - 1; |
return poly.length.signed - 1; |