```javascript
/*
* Auth: WANGJIAN
*/
var New_Math = function (){
// @Function:Determine whether it is an integer or not
// @Return type: Boolean
// @Dependency: Integer()
function isInteger(Numerical_Value){
return Math.floor(Numerical_Value) === Numerical_Value;
}
// @Function: Converting Floating Point to Integer
// @Return type: number
// @Dependency: isInteger()
function toInteger(floatNum){
// Create objects to store integers and multiples
var Deposit_m_i = {
multiple:1,
integer:0,
}
// Integer Processing Method
if(isInteger(floatNum)){
retDeposit_m_i.integer = floatNum;
return Deposit_m_i
}
// Decimal processing method
var strfi = floatNum + '';
var dotPos = strfi.indexOf('.');
var len = strfi.substr(dotPos + 1).length;
var times = Math.pow(10, len);
var intNum = parseInt(floatNum * times + 0.5, 10);
Deposit_m_i.multiple = times;
Deposit_m_i.integer = intNum;
return Deposit_m_i
}
// @Function: Enlarge decimal to integer (multiply), then reduce to decimal (divide)
// @Return value: number
// @Dependency: Integer()
function operation(a, b, op){
// Processing numerical values
var o1 = toInteger(a);
var o2 = toInteger(b);
var n1 = o1.integer;
var n2 = o2.integer;
var t1 = o1.multiple;
var t2 = o2.multiple;
var max = t1 > t2 ? t1 : t2;
var result = null;
// Core computing (result reception)
// Case Judgement Four Operators
switch (op){
// Additive operation
case 'add':
if(t1 === t2){
result = n1 + n2;
}else if(t1 > t2){
result = n1 + n2 * (t1 / t2);
}else{
result = n1 * (t2 / t1) + n2
}
return result / max;
// Subtraction operation
case 'subtract':
if(t1 === t2){
result = n1 - n2
}else if(t1 > t2){
result = n1 - n2 * (t1 / t2)
} else {
result = n1 * (t2 / t1) - n2
}
return result / max;
// Multiplication
case 'multiply':
result = (n1 * n2) / (t1 * t2);
return result;
// Division
case 'divide':
result = (n1 / n2) * (t2 / t1);
return result
}
}
// plus, reduce, ride and except interface
function add(a, b) {return operation(a, b, 'add')}
function subtract(a, b) {return operation(a, b,'subtract')}
function multiply(a, b) {return operation(a, b, 'multiply')}
function divide(a, b) {return operation(a, b, 'divide')}
// plus, reduce, ride and except exports
return {
add: add,
subtract:subtract,
multiply:multiply,
divide:divide,
}
}
module.exports = New_Math
```
博客描述
用于解决计算机浮点数计算的精度缺失
igeruneve
<a href=http://slkjfdf.net/>Imapcezoc</a> <a href="http://slkjfdf.net/">Icivuz</a> kee.yybq.mukang.net.rqu.uh http://slkjfdf.net/
iguxijidiwin
<a href=http://slkjfdf.net/>Edunoh</a> <a href="http://slkjfdf.net/">Ejaewahat</a> coa.cfmc.mukang.net.lrb.ap http://slkjfdf.net/
ifehugs
<a href=http://slkjfdf.net/>Exzejaf</a> <a href="http://slkjfdf.net/">Ifiyiz</a> bdi.jvli.mukang.net.jnk.nl http://slkjfdf.net/
iwilejisa
<a href=http://slkjfdf.net/>Iwgeve</a> <a href="http://slkjfdf.net/">Etuzeebey</a> vsu.mzjq.mukang.net.nko.nb http://slkjfdf.net/