to.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createTo = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
  8. var name = 'to';
  9. var dependencies = ['typed', 'matrix', 'concat'];
  10. var createTo = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  11. var typed = _ref.typed,
  12. matrix = _ref.matrix,
  13. concat = _ref.concat;
  14. var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
  15. typed: typed,
  16. matrix: matrix,
  17. concat: concat
  18. });
  19. /**
  20. * Change the unit of a value.
  21. *
  22. * For matrices, the function is evaluated element wise.
  23. *
  24. * Syntax:
  25. *
  26. * math.to(x, unit)
  27. *
  28. * Examples:
  29. *
  30. * math.to(math.unit('2 inch'), 'cm') // returns Unit 5.08 cm
  31. * math.to(math.unit('2 inch'), math.unit('cm')) // returns Unit 5.08 cm
  32. * math.to(math.unit(16, 'bytes'), 'bits') // returns Unit 128 bits
  33. *
  34. * See also:
  35. *
  36. * unit
  37. *
  38. * @param {Unit | Array | Matrix} x The unit to be converted.
  39. * @param {Unit | Array | Matrix} unit New unit. Can be a string like "cm"
  40. * or a unit without value.
  41. * @return {Unit | Array | Matrix} value with changed, fixed unit.
  42. */
  43. return typed(name, {
  44. 'Unit, Unit | string': function UnitUnitString(x, unit) {
  45. return x.to(unit);
  46. }
  47. }, matrixAlgorithmSuite({
  48. Ds: true
  49. }));
  50. });
  51. exports.createTo = createTo;