mirror of
https://github.com/josdejong/mathjs.git
synced 2026-02-01 16:07:46 +00:00
Fixed #625: Unit in (inch) not always working due to ambiguity with
the operator `a in b` (alias of `a to b`)
This commit is contained in:
parent
bbfa7d51df
commit
5b682d6040
@ -11,6 +11,8 @@
|
||||
- Fixed #629: expression parser throws an error when passing a number with
|
||||
decimal exponent instead of parsing them as implicit multiplication.
|
||||
- Fixed #484, #555: inaccuracy of `math.sinh` for values between -1 and 1.
|
||||
- Fixed #625: Unit `in` (`inch`) not always working due to ambiguity with
|
||||
the operator `a in b` (alias of `a to b`).
|
||||
|
||||
|
||||
## 2016-03-24, version 3.1.3
|
||||
|
||||
@ -783,8 +783,15 @@ function factory (type, config, load, typed) {
|
||||
fn = operators[name];
|
||||
|
||||
getTokenSkipNewline();
|
||||
params = [node, parseRange()];
|
||||
node = new OperatorNode(name, fn, params);
|
||||
|
||||
if (token === '') { // end of expression -> this is the unit 'in' ('inch')
|
||||
node = new OperatorNode('*', 'multiply', [node, new SymbolNode('in')], true);
|
||||
}
|
||||
else {
|
||||
// operator 'a to b' or 'a in b'
|
||||
params = [node, parseRange()];
|
||||
node = new OperatorNode(name, fn, params);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
|
||||
@ -384,9 +384,9 @@ describe('parse', function() {
|
||||
approx.deepEqual(parseAndEval('2 in to meter'), new Unit(2, 'inch').to('meter'));
|
||||
approx.deepEqual(parseAndEval('2 in in meter'), new Unit(2, 'inch').to('meter'));
|
||||
approx.deepEqual(parseAndEval('a in inch', {a: new Unit(5.08, 'cm')}), new Unit(2, 'inch').to('inch'));
|
||||
// Note: the following is not supported (due to conflicts):
|
||||
//approx.deepEqual(parseAndEval('(2+3) in'), new Unit(5, 'inch'));
|
||||
//approx.deepEqual(parseAndEval('a in', {a: 5}), new Unit(5, 'inch'));
|
||||
approx.deepEqual(parseAndEval('(2+3) in'), new Unit(5, 'in'));
|
||||
approx.deepEqual(parseAndEval('a in', {a: 5}), new Unit(5, 'in'));
|
||||
approx.deepEqual(parseAndEval('0.5in + 1.5in to cm'), new Unit(5.08, 'cm').to('cm'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user