mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
module.exports = function (math) {
|
|
var util = require('../../util/index'),
|
|
|
|
Complex = require('../../type/Complex'),
|
|
collection = require('../../type/collection'),
|
|
|
|
isNumBool = util.number.isNumBool,
|
|
isCollection =collection.isCollection,
|
|
isComplex = Complex.isComplex;
|
|
|
|
/**
|
|
* Round a value towards plus infinity
|
|
*
|
|
* ceil(x)
|
|
*
|
|
* For matrices, the function is evaluated element wise.
|
|
*
|
|
* @param {Number | Boolean | Complex | Array | Matrix} x
|
|
* @return {Number | Complex | Array | Matrix} res
|
|
*/
|
|
math.ceil = function ceil(x) {
|
|
if (arguments.length != 1) {
|
|
throw new util.error.ArgumentsError('ceil', arguments.length, 1);
|
|
}
|
|
|
|
if (isNumBool(x)) {
|
|
return Math.ceil(x);
|
|
}
|
|
|
|
if (isComplex(x)) {
|
|
return new Complex (
|
|
Math.ceil(x.re),
|
|
Math.ceil(x.im)
|
|
);
|
|
}
|
|
|
|
if (isCollection(x)) {
|
|
return collection.deepMap(x, ceil);
|
|
}
|
|
|
|
if (x.valueOf() !== x) {
|
|
// fallback on the objects primitive value
|
|
return ceil(x.valueOf());
|
|
}
|
|
|
|
throw new util.error.UnsupportedTypeError('ceil', x);
|
|
};
|
|
};
|