UNPKG

hyperformula-dc

Version:

HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas

351 lines (312 loc) 11.5 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } require("core-js/modules/es.reflect.construct.js"); require("core-js/modules/es.symbol.js"); require("core-js/modules/es.symbol.description.js"); require("core-js/modules/es.object.to-string.js"); require("core-js/modules/es.symbol.iterator.js"); require("core-js/modules/es.array.iterator.js"); require("core-js/modules/es.string.iterator.js"); require("core-js/modules/web.dom-collections.iterator.js"); exports.__esModule = true; exports.TrigonometryPlugin = void 0; require("core-js/modules/es.math.sinh.js"); require("core-js/modules/es.math.asinh.js"); require("core-js/modules/es.math.cosh.js"); require("core-js/modules/es.math.acosh.js"); require("core-js/modules/es.math.tanh.js"); require("core-js/modules/es.math.atanh.js"); require("core-js/modules/es.object.get-prototype-of.js"); var _Cell = require("../../Cell"); var _errorMessage = require("../../error-message"); var _FunctionPlugin2 = require("./FunctionPlugin"); var _MathConstantsPlugin = require("./MathConstantsPlugin"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Interpreter plugin containing trigonometric functions */ var TrigonometryPlugin = /*#__PURE__*/function (_FunctionPlugin) { _inherits(TrigonometryPlugin, _FunctionPlugin); var _super = _createSuper(TrigonometryPlugin); function TrigonometryPlugin() { _classCallCheck(this, TrigonometryPlugin); return _super.apply(this, arguments); } _createClass(TrigonometryPlugin, [{ key: "acos", value: /** * Corresponds to ACOS(value) * * Returns the arc cosine (or inverse cosine) of a number. * * @param ast * @param state */ function acos(ast, state) { return this.runFunction(ast.args, state, this.metadata('ACOS'), Math.acos); } }, { key: "asin", value: function asin(ast, state) { return this.runFunction(ast.args, state, this.metadata('ASIN'), Math.asin); } }, { key: "cos", value: function cos(ast, state) { return this.runFunction(ast.args, state, this.metadata('COS'), Math.cos); } }, { key: "sin", value: function sin(ast, state) { return this.runFunction(ast.args, state, this.metadata('SIN'), Math.sin); } }, { key: "tan", value: function tan(ast, state) { return this.runFunction(ast.args, state, this.metadata('TAN'), Math.tan); } }, { key: "atan", value: function atan(ast, state) { return this.runFunction(ast.args, state, this.metadata('ATAN'), Math.atan); } }, { key: "atan2", value: function atan2(ast, state) { return this.runFunction(ast.args, state, this.metadata('ATAN2'), function (x, y) { if (x === 0 && y === 0) { return new _Cell.CellError(_Cell.ErrorType.DIV_BY_ZERO); } return Math.atan2(y, x); }); } }, { key: "cot", value: function cot(ast, state) { return this.runFunction(ast.args, state, this.metadata('COT'), function (arg) { return arg === 0 ? new _Cell.CellError(_Cell.ErrorType.DIV_BY_ZERO) : 1 / Math.tan(arg); }); } }, { key: "acot", value: function acot(ast, state) { return this.runFunction(ast.args, state, this.metadata('ACOT'), function (arg) { return arg === 0 ? _MathConstantsPlugin.PI / 2 : Math.atan(1 / arg); }); } }, { key: "sec", value: function sec(ast, state) { return this.runFunction(ast.args, state, this.metadata('SEC'), function (arg) { return 1 / Math.cos(arg); }); } }, { key: "csc", value: function csc(ast, state) { return this.runFunction(ast.args, state, this.metadata('CSC'), function (arg) { return arg === 0 ? new _Cell.CellError(_Cell.ErrorType.DIV_BY_ZERO) : 1 / Math.sin(arg); }); } }, { key: "sinh", value: function sinh(ast, state) { return this.runFunction(ast.args, state, this.metadata('SINH'), Math.sinh); } }, { key: "asinh", value: function asinh(ast, state) { return this.runFunction(ast.args, state, this.metadata('ASINH'), Math.asinh); } }, { key: "cosh", value: function cosh(ast, state) { return this.runFunction(ast.args, state, this.metadata('COSH'), Math.cosh); } }, { key: "acosh", value: function acosh(ast, state) { return this.runFunction(ast.args, state, this.metadata('ACOSH'), Math.acosh); } }, { key: "tanh", value: function tanh(ast, state) { return this.runFunction(ast.args, state, this.metadata('TANH'), Math.tanh); } }, { key: "atanh", value: function atanh(ast, state) { return this.runFunction(ast.args, state, this.metadata('ATANH'), Math.atanh); } }, { key: "coth", value: function coth(ast, state) { return this.runFunction(ast.args, state, this.metadata('COTH'), function (arg) { return arg === 0 ? new _Cell.CellError(_Cell.ErrorType.DIV_BY_ZERO) : 1 / Math.tanh(arg); }); } }, { key: "acoth", value: function acoth(ast, state) { return this.runFunction(ast.args, state, this.metadata('ACOTH'), function (arg) { return arg === 0 ? new _Cell.CellError(_Cell.ErrorType.NUM, _errorMessage.ErrorMessage.NonZero) : Math.atanh(1 / arg); }); } }, { key: "sech", value: function sech(ast, state) { return this.runFunction(ast.args, state, this.metadata('SECH'), function (arg) { return 1 / Math.cosh(arg); }); } }, { key: "csch", value: function csch(ast, state) { return this.runFunction(ast.args, state, this.metadata('CSCH'), function (arg) { return arg === 0 ? new _Cell.CellError(_Cell.ErrorType.DIV_BY_ZERO) : 1 / Math.sinh(arg); }); } }]); return TrigonometryPlugin; }(_FunctionPlugin2.FunctionPlugin); exports.TrigonometryPlugin = TrigonometryPlugin; TrigonometryPlugin.implementedFunctions = { 'ACOS': { method: 'acos', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ASIN': { method: 'asin', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'COS': { method: 'cos', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'SIN': { method: 'sin', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'TAN': { method: 'tan', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ATAN': { method: 'atan', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ATAN2': { method: 'atan2', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }, { argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'COT': { method: 'cot', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'SEC': { method: 'sec', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'CSC': { method: 'csc', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'SINH': { method: 'sinh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'COSH': { method: 'cosh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'TANH': { method: 'tanh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'COTH': { method: 'coth', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'SECH': { method: 'sech', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'CSCH': { method: 'csch', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ACOT': { method: 'acot', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ASINH': { method: 'asinh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ACOSH': { method: 'acosh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ATANH': { method: 'atanh', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] }, 'ACOTH': { method: 'acoth', parameters: [{ argumentType: _FunctionPlugin2.ArgumentTypes.NUMBER }] } };