Long multiplication: Difference between revisions

Content added Content deleted
m (→‎Functional (ES 5): Removed a couple of unused parameter names from a .reduce function)
Line 2,398: Line 2,398:
// Javascript lacks an unbounded integer type
// Javascript lacks an unbounded integer type
// so this multiplication function needs arbitrary precision integer string arguments
// so this multiplication function takes and returns
// (rather than native integer arguments) for full precision at scales beyond c. 2^54
// long integer strings rather than any kind of native integer


Line 2,407: Line 2,407:
digitProducts(digits(num1), digits(num2))
digitProducts(digits(num1), digits(num2))
);
);
}


}


// digitProducts :: [Int] -> [Int] -> [Int]
// digitProducts :: [Int] -> [Int] -> [Int]
Line 2,436: Line 2,436:
function largeIntegerString(lstColumnValues) {
function largeIntegerString(lstColumnValues) {
var dctProduct = lstColumnValues
var dctProduct = lstColumnValues
.reduceRight(function (a, x, i, l) {
.reduceRight(function (a, x) {
var intSum = x + a.carried,
var intSum = x + a.carried,
intDigit = intSum % 10;
intDigit = intSum % 10;