...
'+': {
precedence: 1,
implementation: (l: number, r: number): number => {
return l + r;
},
}
...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Nemathode from 'nemathode'; | |
import { config } from './config'; | |
const nemathode = Nemathode({ | |
...config, | |
}); | |
// method for expression evaluation | |
const res = nemathode.evaluate([...]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toOutputValue = (val: unknown): number | boolean => { | |
if (val instanceof Decimal) { | |
return val.toNumber(); | |
} | |
return val; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toInputType = (val: unknown): Decimal | unknown => { | |
if (typeof val === 'number') { | |
const input = new Decimal(val); | |
return input; | |
} | |
return val; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = { | |
mathConstants: { | |
'E': Math.E, | |
'LN2': Math.LN2, | |
'LN10': Math.LN10, | |
'LOG10E': Math.LOG10E, | |
'LOG2E': Math.LOG2E, | |
'PI': Math.PI, | |
'SQRT1_2': Math.SQRT1_2, | |
'SQRT2': Math.SQRT2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resOfNestedExp = nemathode.evaluate([1, '+', 'PI', '*', ['abs', 1, 2, 3], '-', [1, '+', [1, '/', 25]]]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const piConst = nemathode.mathConstants.PI; | |
const piConstInUse = nemathode.evaluate([1, '+', 'PI']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const customFunction = nemathode.evaluate([1, '+', ['abs', 1, 2, 3]]); //a rguments are not evaluated (future) | |
const singleFunction = nemathode.evaluate([['abs', 1, 2, 3]]; // single function syntax (it's not convinient, but for now it's only way) | |
const boolResult = nemathode.evaluate([['areEqual', 1, 2, 3]]); // returns boolean | |
// etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sumOperator = nemathode.evaluate([1, '+', 1]); // 2 | |
const mulOperator = nemathode.evaluate([1, '*', 1]); // 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const res1 = nemathode.evaluate([0, '+', 1]); // 1 | |
const res2 = nemathode.evaluate([0, '+', 1, '*', [2, '/', 1, '-', 3]); // -1 |
NewerOlder