Skip to content

Commit efd34dd

Browse files
committed
refactor: Remove the automatic conversion from number to string.
This is a breaking change. However, nothing in the unit tests or examples actually depended on such a conversion, and it's difficult to construct situations in which it's necessary. The best such example is e.g. `count(57)` which formerly gave the number of digits in its numeric argument. Of course, after this commit, that behavior can still be obtained by the just slightly longer expression `count(string(57))` The change is proposed in preparation for an addition of new facilities/ handlers to allow symbolic computation in a couple of different ways (see #2475 and #2470).
1 parent 1a3401e commit efd34dd

File tree

9 files changed

+14
-21
lines changed

9 files changed

+14
-21
lines changed

src/core/function/typed.js

-6
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ export const createTyped = /* #__PURE__ */ factory('typed', dependencies, functi
179179

180180
return new Complex(x, 0)
181181
}
182-
}, {
183-
from: 'number',
184-
to: 'string',
185-
convert: function (x) {
186-
return x + ''
187-
}
188182
}, {
189183
from: 'BigNumber',
190184
to: 'Complex',

src/type/unit/Unit.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
8282
this.units = u.units
8383
this.dimensions = u.dimensions
8484
} else {
85-
this.units = [
86-
{
87-
unit: UNIT_NONE,
88-
prefix: PREFIXES.NONE, // link to a list with supported prefixes
89-
power: 0
90-
}
91-
]
85+
this.units = []
9286
this.dimensions = []
9387
for (let i = 0; i < BASE_DIMENSIONS.length; i++) {
9488
this.dimensions[i] = 0

src/type/unit/function/unit.js

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export const createUnitFunction = /* #__PURE__ */ factory(name, dependencies, ({
4747
return new Unit(value, unit)
4848
},
4949

50+
'number | BigNumber | Fraction': function (value) {
51+
// dimensionless
52+
return new Unit(value)
53+
},
54+
5055
'Array | Matrix': function (x) {
5156
return deepMap(x, this)
5257
}

test/unit-tests/function/algebra/derivative.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe('derivative', function () {
254254
it('should throw error for incorrect argument types', function () {
255255
assert.throws(function () {
256256
derivative('42', '42')
257-
}, /TypeError: Unexpected type of argument in function derivative \(expected: string or SymbolNode or number or boolean, actual: ConstantNode, index: 1\)/)
257+
}, /TypeError: Unexpected type of argument in function derivative \(expected: string or SymbolNode or boolean, actual: ConstantNode, index: 1\)/)
258258

259259
assert.throws(function () {
260260
derivative('[1, 2; 3, 4]', 'x')
@@ -268,7 +268,7 @@ describe('derivative', function () {
268268
it('should throw error if incorrect number of arguments', function () {
269269
assert.throws(function () {
270270
derivative('x + 2')
271-
}, /TypeError: Too few arguments in function derivative \(expected: string or SymbolNode or number or boolean, index: 1\)/)
271+
}, /TypeError: Too few arguments in function derivative \(expected: string or SymbolNode or boolean, index: 1\)/)
272272

273273
assert.throws(function () {
274274
derivative('x + 2', 'x', {}, true, 42)

test/unit-tests/function/matrix/count.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('count', function () {
3131

3232
it('should throw an error if called with an invalid number of arguments', function () {
3333
assert.throws(function () { count() }, /TypeError: Too few arguments/)
34-
assert.throws(function () { count(1, 2) }, /TypeError: Too many arguments/)
34+
assert.throws(function () { count([1], 2) }, /TypeError: Too many arguments/)
3535
})
3636

3737
it('should throw an error if called with invalid type of arguments', function () {

test/unit-tests/function/matrix/diag.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('diag', function () {
108108

109109
it('should throw an error in case of wrong number of arguments', function () {
110110
assert.throws(function () { math.diag() }, /TypeError: Too few arguments/)
111-
assert.throws(function () { math.diag([], 2, 3, 4) }, /TypeError: Too many arguments/)
111+
assert.throws(function () { math.diag([], 2, 'dense', 4) }, /TypeError: Too many arguments/)
112112
})
113113

114114
it('should throw an error in case of invalid type of arguments', function () {

test/unit-tests/function/unit/to.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('to', function () {
7070

7171
it('should throw an error if called with a number', function () {
7272
assert.throws(function () { math.to(5, unit('m')) }, TypeError)
73-
assert.throws(function () { math.to(unit('5cm'), 2) }, /SyntaxError: "2" contains no units/)
73+
assert.throws(function () { math.to(unit('5cm'), 2) }, TypeError)
7474
})
7575

7676
it('should throw an error if called with a string', function () {

test/unit-tests/type/matrix/function/matrix.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ describe('matrix', function () {
8585
})
8686

8787
it('should throw an error if called with too many arguments', function () {
88-
assert.throws(function () { matrix([], 3, 3, 7) }, /TypeError: Too many arguments/)
88+
assert.throws(function () { matrix([], 'dense', 'number', 7) }, /TypeError: Too many arguments/)
8989
})
9090

9191
it('should throw an error when called with an invalid storage format', function () {
92-
assert.throws(function () { math.matrix([], 1) }, /TypeError: Unknown matrix type "1"/)
92+
assert.throws(function () { math.matrix([], '1') }, /TypeError: Unknown matrix type "1"/)
9393
})
9494

9595
it('should throw an error when called with an unknown storage format', function () {

test/unit-tests/type/matrix/function/sparse.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('sparse', function () {
4040
})
4141

4242
it('should throw an error if called with too many arguments', function () {
43-
assert.throws(function () { sparse([], 3, 3) }, /TypeError: Too many arguments/)
43+
assert.throws(function () { sparse([], 'number', 3) }, /TypeError: Too many arguments/)
4444
})
4545

4646
it('should LaTeX matrix', function () {

0 commit comments

Comments
 (0)