bin.js 884 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { factory } from '../../utils/factory.js';
  2. var name = 'bin';
  3. var dependencies = ['typed', 'format'];
  4. /**
  5. * Format a number as binary.
  6. *
  7. * Syntax:
  8. *
  9. * math.bin(value)
  10. *
  11. * Examples:
  12. *
  13. * //the following outputs "0b10"
  14. * math.bin(2)
  15. *
  16. * See also:
  17. *
  18. * oct
  19. * hex
  20. *
  21. * @param {number} value Value to be stringified
  22. * @param {number} wordSize Optional word size (see `format`)
  23. * @return {string} The formatted value
  24. */
  25. export var createBin = factory(name, dependencies, _ref => {
  26. var {
  27. typed,
  28. format
  29. } = _ref;
  30. return typed(name, {
  31. 'number | BigNumber': function numberBigNumber(n) {
  32. return format(n, {
  33. notation: 'bin'
  34. });
  35. },
  36. 'number | BigNumber, number': function numberBigNumberNumber(n, wordSize) {
  37. return format(n, {
  38. notation: 'bin',
  39. wordSize
  40. });
  41. }
  42. });
  43. });