|
|
@ -23,7 +23,7 @@ export function add(num, arg) { |
|
|
|
c = Math.abs(r1 - r2); |
|
|
|
c = Math.abs(r1 - r2); |
|
|
|
m = Math.pow(10, Math.max(r1, r2)); |
|
|
|
m = Math.pow(10, Math.max(r1, r2)); |
|
|
|
if (c > 0) { |
|
|
|
if (c > 0) { |
|
|
|
let cm = Math.pow(10, c); |
|
|
|
const cm = Math.pow(10, c); |
|
|
|
if (r1 > r2) { |
|
|
|
if (r1 > r2) { |
|
|
|
arg1 = Number(arg1.toString().replace(".", "")); |
|
|
|
arg1 = Number(arg1.toString().replace(".", "")); |
|
|
|
arg2 = Number(arg2.toString().replace(".", "")) * cm; |
|
|
|
arg2 = Number(arg2.toString().replace(".", "")) * cm; |
|
|
@ -101,8 +101,8 @@ export function div(num, arg) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function digitLength(num) { |
|
|
|
function digitLength(num) { |
|
|
|
// Get digit length of e
|
|
|
|
// Get digit length of e
|
|
|
|
let eSplit = num.toString().split(/[eE]/); |
|
|
|
const eSplit = num.toString().split(/[eE]/); |
|
|
|
let len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); |
|
|
|
const len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); |
|
|
|
return len > 0 ? len : 0; |
|
|
|
return len > 0 ? len : 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -114,7 +114,7 @@ export function div(num, arg) { |
|
|
|
if (num.toString().indexOf("e") === -1) { |
|
|
|
if (num.toString().indexOf("e") === -1) { |
|
|
|
return Number(num.toString().replace(".", "")); |
|
|
|
return Number(num.toString().replace(".", "")); |
|
|
|
} |
|
|
|
} |
|
|
|
let dLen = digitLength(num); |
|
|
|
const dLen = digitLength(num); |
|
|
|
return dLen > 0 ? num * Math.pow(10, dLen) : num; |
|
|
|
return dLen > 0 ? num * Math.pow(10, dLen) : num; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -122,17 +122,17 @@ export function div(num, arg) { |
|
|
|
* 精确乘法 |
|
|
|
* 精确乘法 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function times(num1, num2) { |
|
|
|
function times(num1, num2) { |
|
|
|
let others = []; |
|
|
|
const others = []; |
|
|
|
for (let _i = 2; _i < arguments.length; _i++) { |
|
|
|
for (let _i = 2; _i < arguments.length; _i++) { |
|
|
|
others[_i - 2] = arguments[_i]; |
|
|
|
others[_i - 2] = arguments[_i]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (others.length > 0) { |
|
|
|
if (others.length > 0) { |
|
|
|
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); |
|
|
|
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); |
|
|
|
} |
|
|
|
} |
|
|
|
let num1Changed = float2Fixed(num1); |
|
|
|
const num1Changed = float2Fixed(num1); |
|
|
|
let num2Changed = float2Fixed(num2); |
|
|
|
const num2Changed = float2Fixed(num2); |
|
|
|
let baseNum = digitLength(num1) + digitLength(num2); |
|
|
|
const baseNum = digitLength(num1) + digitLength(num2); |
|
|
|
let leftValue = num1Changed * num2Changed; |
|
|
|
const leftValue = num1Changed * num2Changed; |
|
|
|
return leftValue / Math.pow(10, baseNum); |
|
|
|
return leftValue / Math.pow(10, baseNum); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -140,15 +140,15 @@ export function div(num, arg) { |
|
|
|
* 精确除法 |
|
|
|
* 精确除法 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function accDivide(num1, num2) { |
|
|
|
function accDivide(num1, num2) { |
|
|
|
let others = []; |
|
|
|
const others = []; |
|
|
|
for (let _i = 2; _i < arguments.length; _i++) { |
|
|
|
for (let _i = 2; _i < arguments.length; _i++) { |
|
|
|
others[_i - 2] = arguments[_i]; |
|
|
|
others[_i - 2] = arguments[_i]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (others.length > 0) { |
|
|
|
if (others.length > 0) { |
|
|
|
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); |
|
|
|
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); |
|
|
|
} |
|
|
|
} |
|
|
|
let num1Changed = float2Fixed(num1); |
|
|
|
const num1Changed = float2Fixed(num1); |
|
|
|
let num2Changed = float2Fixed(num2); |
|
|
|
const num2Changed = float2Fixed(num2); |
|
|
|
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); |
|
|
|
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|