gentooboontoo / js-quantities

JavaScript library for quantity calculation and unit conversion
http://gentooboontoo.github.io/js-quantities/
MIT License
396 stars 102 forks source link

'1 Mohm' interpreted as 'molar ohm' #72

Open kasbah opened 7 years ago

kasbah commented 7 years ago

In electronic engineering 1Mohm is typically 1000,000 Ohm.

> Qty = require('js-quantities')
> k = Qty('1kohm')
Qty {
  scalar: 1,
  baseScalar: 1000,
  signature: -312058,
  _conversionCache: {},
  numerator: [ '<kilo>', '<ohm>' ],
  denominator: [ '<1>' ],
  initValue: '1kohm',
  _isBase: false,
  _units: 'kOhm' }
> m = Qty('1Mohm')
Qty {
  scalar: 1,
  baseScalar: 1000,
  signature: 2887939,
  _conversionCache: {},
  numerator: [ '<molar>', '<ohm>' ],
  denominator: [ '<1>' ],
  initValue: '1Mohm',
  _isBase: false,
  _units: 'M*Ohm' }
> k.eq(m)
Error: Incompatible units
    at QtyError.Error (native)
    at new QtyError (./node_modules/js-quantities/src/quantities.js:1954:17)
    at throwIncompatibleUnits (./node_modules/js-quantities/src/quantities.js:764:11)
    at Qty.compareTo (./node_modules/js-quantities/src/quantities.js:1037:9)
    at Qty.eq (./node_modules/js-quantities/src/quantities.js:890:19)
    at repl:1:3
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)

Additionally it would be great to be able to space things like 1k ohm. Super nice bonus would be to be able to use EE convention of putting the quantifier instead of the decimal e.g. 1k5 ohm.