to.js 1.5 KB

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