mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-24 22:33:16 +00:00
Add some error trapping to maths operators
This commit is contained in:
parent
dd7837d164
commit
86387a9185
|
@ -76,33 +76,33 @@ exports.min = makeNumericBinaryOperator(
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.fixed = makeNumericBinaryOperator(
|
exports.fixed = makeNumericBinaryOperator(
|
||||||
function(a,b) {return Number.prototype.toFixed.call(a,b);}
|
function(a,b) {return Number.prototype.toFixed.call(a,Math.min(Math.max(b,0),100));}
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.precision = makeNumericBinaryOperator(
|
exports.precision = makeNumericBinaryOperator(
|
||||||
function(a,b) {return Number.prototype.toPrecision.call(a,b);}
|
function(a,b) {return Number.prototype.toPrecision.call(a,Math.min(Math.max(b,1),100));}
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.exponential = makeNumericBinaryOperator(
|
exports.exponential = makeNumericBinaryOperator(
|
||||||
function(a,b) {return Number.prototype.toExponential.call(a,b);}
|
function(a,b) {return Number.prototype.toExponential.call(a,Math.min(Math.max(b,0),100));}
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.sum = makeNumericArrayOperator(
|
exports.sum = makeNumericReducingOperator(
|
||||||
function(accumulator,value) {return accumulator + value},
|
function(accumulator,value) {return accumulator + value},
|
||||||
0 // Initial value
|
0 // Initial value
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.product = makeNumericArrayOperator(
|
exports.product = makeNumericReducingOperator(
|
||||||
function(accumulator,value) {return accumulator * value},
|
function(accumulator,value) {return accumulator * value},
|
||||||
1 // Initial value
|
1 // Initial value
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.maxall = makeNumericArrayOperator(
|
exports.maxall = makeNumericReducingOperator(
|
||||||
function(accumulator,value) {return Math.max(accumulator,value)},
|
function(accumulator,value) {return Math.max(accumulator,value)},
|
||||||
-Infinity // Initial value
|
-Infinity // Initial value
|
||||||
);
|
);
|
||||||
|
|
||||||
exports.minall = makeNumericArrayOperator(
|
exports.minall = makeNumericReducingOperator(
|
||||||
function(accumulator,value) {return Math.min(accumulator,value)},
|
function(accumulator,value) {return Math.min(accumulator,value)},
|
||||||
Infinity // Initial value
|
Infinity // Initial value
|
||||||
);
|
);
|
||||||
|
@ -118,7 +118,7 @@ function makeNumericBinaryOperator(fnCalc) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeNumericArrayOperator(fnCalc,initialValue) {
|
function makeNumericReducingOperator(fnCalc,initialValue) {
|
||||||
initialValue = initialValue || 0;
|
initialValue = initialValue || 0;
|
||||||
return function(source,operator,options) {
|
return function(source,operator,options) {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user