to.js 1.3 KB

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