UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

52 lines (50 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTo = void 0; var _factory = require("../../utils/factory.js"); var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js"); var name = 'to'; var dependencies = ['typed', 'matrix', 'concat']; var createTo = exports.createTo = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { var typed = _ref.typed, matrix = _ref.matrix, concat = _ref.concat; var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({ typed: typed, matrix: matrix, concat: concat }); /** * Change the unit of a value. * * For matrices, the function is evaluated element wise. * * Syntax: * * math.to(x, unit) * * Examples: * * math.to(math.unit('2 inch'), 'cm') // returns Unit 5.08 cm * math.to(math.unit('2 inch'), math.unit('cm')) // returns Unit 5.08 cm * math.to(math.unit(16, 'bytes'), 'bits') // returns Unit 128 bits * * See also: * * unit * * @param {Unit | Array | Matrix} x The unit to be converted. * @param {Unit | Array | Matrix} unit New unit. Can be a string like "cm" * or a unit without value. * @return {Unit | Array | Matrix} value with changed, fixed unit. */ return typed(name, { 'Unit, Unit | string': function UnitUnitString(x, unit) { return x.to(unit); } }, matrixAlgorithmSuite({ Ds: true })); });