Merge branch 'develop' into Undo

This commit is contained in:
Veeloxfire 2020-04-08 22:54:54 +01:00 committed by GitHub
commit 79066f1bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,8 @@
# not yet published, version 6.6.3
- Fix #1808: methods `.toNumber()` and `.toNumeric()` not working on a
unitless unit.
- Fix #1645: not being able to use named operators `mod`, `and`, `not`, `or`,
`xor`, `to`, `in` as object keys. Thanks @Veeloxfire.
- Fix `eigs` not using `config.epsilon`.

View File

@ -880,7 +880,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
other = this.clone()
}
if (other._isDerived()) {
if (other._isDerived() || other.units.length === 0) {
return other._denormalize(other.value)
} else {
return other._denormalize(other.value, other.units[0].prefix.value)

View File

@ -231,6 +231,11 @@ describe('Unit', function () {
const u = new Unit(math.fraction(5), 'cm')
assert.strictEqual(u.toNumber('mm'), 50)
})
it('should convert a unit with value only to a number', function () {
const u = Unit.parse('5', { allowNoUnits: true })
assert.strictEqual(u.toNumber(), 5)
})
})
describe('toNumeric', function () {
@ -349,6 +354,11 @@ describe('Unit', function () {
assert.strictEqual(u4.fixPrefix, true)
})
it('should convert a unitless quantity', function () {
const u = Unit.parse('5', { allowNoUnits: true })
assert.strictEqual(u.toNumeric(), 5)
})
it('should convert a binary prefixes (1)', function () {
const u1 = new Unit(1, 'Kib')
assert.strictEqual(u1.value, 1024)