mirror of
https://github.com/josdejong/mathjs.git
synced 2026-02-01 16:07:46 +00:00
Merge branch 'develop' into Undo
This commit is contained in:
commit
79066f1bce
@ -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`.
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user