Polynomial long division: Difference between revisions
Content added Content deleted
(Updated D entry) |
(Updated D entry) |
||
Line 687: | Line 687: | ||
((0 . -123)) ; -123</lang> |
((0 . -123)) ; -123</lang> |
||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio, std.range, std.algorithm, std.typecons, std. |
<lang d>import std.stdio, std.range, std.algorithm, std.typecons, std.conv; |
||
Tuple!(double[], double[]) polyDiv(in double[] inN, in double[] inD) |
Tuple!(double[], double[]) polyDiv(in double[] inN, in double[] inD) |
||
Line 694: | Line 694: | ||
static int trimAndDegree(T)(ref T[] poly) nothrow pure { |
static int trimAndDegree(T)(ref T[] poly) nothrow pure { |
||
poly = poly.retro.find!q{ a != b }(0.0).retro; |
poly = poly.retro.find!q{ a != b }(0.0).retro; |
||
return |
return poly.length.signed - 1; |
||
} |
} |
||
Line 721: | Line 721: | ||
int trimAndDegree1(T)(ref T[] poly) nothrow pure { |
int trimAndDegree1(T)(ref T[] poly) nothrow pure { |
||
poly.length -= poly.retro.countUntil!q{ a != 0 }; |
poly.length -= poly.retro.countUntil!q{ a != 0 }; |
||
return |
return poly.length.signed - 1; |
||
} |
} |
||