Skip to content

Commit 07b7906

Browse files
committed
fix and test for issue #57
1 parent af3c6bd commit 07b7906

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

nerdamer.core.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -6382,7 +6382,12 @@ var nerdamer = (function (imports) {
63826382

63836383
//only even bother to check if the string contains e. This regex is painfully slow and might need a better solution. e.g. hangs on (0.06/3650))^(365)
63846384
if(/e/gi.test(e)) {
6385-
e = e.replace(/\-*\d+\.*\d*e\+?\-?\d+/gi, function (x) {
6385+
// negative numbers
6386+
e = e.replace(/\-+\d+\.?\d*e\+?\-?\d+/gi, function (x) {
6387+
return scientificToDecimal(x);
6388+
});
6389+
// positive numbers that are not part of an identifier
6390+
e = e.replace(/(?<![A-Za-z])\d+\.?\d*e\+?\-?\d+/gi, function (x) {
63866391
return scientificToDecimal(x);
63876392
});
63886393
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "javascript light-weight symbolic math library",
77
"name": "nerdamer-prime",
88
"license": "MIT",
9-
"version": "1.2.3",
9+
"version": "1.2.4",
1010
"homepage": "https://github.com/together-science/nerdamer-prime",
1111
"directory": {
1212
"lib": "./"

spec/core.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,11 @@ describe('Nerdamer core', function () {
19551955
nerdamer.clearVars();
19561956
expect(nerdamer('aa').text()).toEqual('aa');
19571957
});
1958+
1959+
it('should parse variables with scientific number patterns in the subscript', function () {
1960+
expect(nerdamer('x_a1e1').text()).toEqual('x_a1e1');
1961+
});
1962+
19581963
});
19591964

19601965
describe('User functions 1', function () {

spec/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let text;
3939
let x;
4040

4141
try {
42-
x = nerdamer("dot(1,2)");
42+
x = nerdamer("x_a1e1");
4343
console.log(x.text());
4444
} catch (error) {
4545
console.log("error "+error)

0 commit comments

Comments
 (0)