Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 078f1dd

Browse files
committed
Renamed methods .eval to .evaluate, updated all docs and examples accordingly
1 parent 90cc28a commit 078f1dd

93 files changed

Lines changed: 807 additions & 771 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ and supports
5050
const math = require('mathjs')
5151

5252
// functions and constants
53-
math.round(math.e, 3) // 2.718
54-
math.atan2(3, -3) / math.pi // 0.75
55-
math.log(10000, 10) // 4
56-
math.sqrt(-4) // 2i
57-
math.pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
58-
math.derivative('x^2 + x', 'x') // 2 * x + 1
53+
math.round(math.e, 3) // 2.718
54+
math.atan2(3, -3) / math.pi // 0.75
55+
math.log(10000, 10) // 4
56+
math.sqrt(-4) // 2i
57+
math.pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
58+
math.derivative('x^2 + x', 'x') // 2 * x + 1
5959

6060
// expressions
61-
math.eval('12 / (2.3 + 0.7)') // 4
62-
math.eval('12.7 cm to inch') // 5 inch
63-
math.eval('sin(45 deg) ^ 2') // 0.5
64-
math.eval('9 / 3 + 2i') // 3 + 2i
65-
math.eval('det([-1, 2 3, 1])') // -7
61+
math.evaluate('12 / (2.3 + 0.7)') // 4
62+
math.evaluate('12.7 cm to inch') // 5 inch
63+
math.evaluate('sin(45 deg) ^ 2') // 0.5
64+
math.evaluate('9 / 3 + 2i') // 3 + 2i
65+
math.evaluate('det([-1, 2 3, 1])') // -7
6666

6767
// chaining
6868
math.chain(3)

benchmark/expression_parser.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const compiled = math.parse(expr).compile(math, {})
2424
const sin = getSafeProperty(math, 'sin')
2525
const pi = getSafeProperty(math, 'pi')
2626
const compiledPlainJs = {
27-
eval: function (scope) {
27+
evaluate: function (scope) {
2828
return 2 + 3 * ('sin' in scope ? getSafeProperty(scope, 'sin') : sin)(('pi' in scope ? getSafeProperty(scope, 'pi') : pi) / 4) - 4 * scope['x']
2929
}
3030
}
@@ -35,23 +35,23 @@ console.log('expression:', expr)
3535
console.log('scope:', scope)
3636
console.log('result:', correctResult)
3737

38-
assertApproxEqual(compiled.eval(scope), correctResult, 1e-7)
39-
assertApproxEqual(compiledPlainJs.eval(scope), correctResult, 1e-7)
38+
assertApproxEqual(compiled.evaluate(scope), correctResult, 1e-7)
39+
assertApproxEqual(compiledPlainJs.evaluate(scope), correctResult, 1e-7)
4040

4141
let total = 0
4242
let nodes = []
4343

4444
const suite = new Benchmark.Suite()
4545
suite
4646
.add(pad('(plain js) evaluate'), function () {
47-
total += compiledPlainJs.eval(scope)
47+
total += compiledPlainJs.evaluate(scope)
4848
})
4949

5050
.add(pad('(mathjs) evaluate'), function () {
51-
total += compiled.eval(scope)
51+
total += compiled.evaluate(scope)
5252
})
5353
.add(pad('(mathjs) parse, compile, evaluate'), function () {
54-
total += math.parse(expr).compile().eval(scope)
54+
total += math.parse(expr).compile().evaluate(scope)
5555
})
5656
.add(pad('(mathjs) parse, compile'), function () {
5757
const node = math.parse(expr).compile()

bin/cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ function runStream (input, output, mode, parenthesis) {
212212
break
213213
}
214214
switch (mode) {
215-
case 'eval':
215+
case 'evaluate':
216216
// evaluate expression
217217
try {
218218
let node = math.parse(expr)
219-
let res = node.eval(scope)
219+
let res = node.evaluate(scope)
220220

221221
if (math.type.isResultSet(res)) {
222222
// we can have 0 or 1 results in the ResultSet, as the CLI
@@ -356,7 +356,7 @@ function outputHelp () {
356356
* Process input and output, based on the command line arguments
357357
*/
358358
const scripts = [] // queue of scripts that need to be processed
359-
let mode = 'eval' // one of 'eval', 'tex' or 'string'
359+
let mode = 'evaluate' // one of 'evaluate', 'tex' or 'string'
360360
let parenthesis = 'keep'
361361
let version = false
362362
let help = false
@@ -414,7 +414,7 @@ if (version) {
414414
} else {
415415
fs.stat(scripts[0], function (e, f) {
416416
if (e) {
417-
console.log(getMath().eval(scripts.join(' ')).toString())
417+
console.log(getMath().evaluate(scripts.join(' ')).toString())
418418
} else {
419419
// work through the queue of scripts
420420
scripts.forEach(function (arg) {

docs/core/configuration.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The following configuration options are available:
2929
a number as input will return a number as output,
3030
a BigNumber as input returns a BigNumber as output.
3131

32-
For example the functions `math.eval('2+3')`, `math.parse('2+3')`,
32+
For example the functions `math.evaluate('2+3')`, `math.parse('2+3')`,
3333
`math.range('1:10')`, and `math.unit('5cm')` use the `number` configuration
3434
setting. But `math.sqrt(4)` will always return the number `2`
3535
regardless of the `number` configuration, because the input is a number.
@@ -65,34 +65,34 @@ This section shows a number of configuration examples.
6565
const math = require('mathjs')
6666

6767
// range will output a Matrix
68-
math.range(0, 4) // Matrix [0, 1, 2, 3]
68+
math.range(0, 4) // Matrix [0, 1, 2, 3]
6969

7070

7171
// create a new instance configured to use Arrays
7272
const math2 = math.create({
73-
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
73+
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
7474
})
7575

7676
// range will output an Array
77-
math2.range(0, 4) // Array [0, 1, 2, 3]
77+
math2.range(0, 4) // Array [0, 1, 2, 3]
7878

7979
// change the configuration of math2 from Arrays to Matrices
8080
math2.config({
81-
matrix: 'Matrix' // Choose 'Matrix' (default) or 'Array'
81+
matrix: 'Matrix' // Choose 'Matrix' (default) or 'Array'
8282
})
8383

8484
// range will output a Matrix
85-
math2.range(0, 4) // Matrix [0, 1, 2, 3]
85+
math2.range(0, 4) // Matrix [0, 1, 2, 3]
8686

8787

8888
// create an instance of math.js with BigNumber configuration
8989
const bigmath = math.create({
90-
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
91-
precision: 32 // 64 by default, only applicable for BigNumbers
90+
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
91+
precision: 32 // 64 by default, only applicable for BigNumbers
9292
})
9393

9494
// parser will parse numbers as BigNumber now:
95-
bigmath.eval('1 / 3') // BigNumber, 0.33333333333333333333333333333333
95+
bigmath.evaluate('1 / 3') // BigNumber, 0.33333333333333333333333333333333
9696
```
9797

9898
### browser
@@ -109,24 +109,24 @@ bigmath.eval('1 / 3') // BigNumber, 0.33333333333333333333333333333333
109109
// the default instance of math.js is available as 'math'
110110
111111
// range will output a Matrix
112-
math.range(0, 4) // Matrix [0, 1, 2, 3]
112+
math.range(0, 4) // Matrix [0, 1, 2, 3]
113113
114114
// change the configuration of math from Matrices to Arrays
115115
math.config({
116-
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
116+
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
117117
})
118118
119119
// range will output an Array
120-
math.range(0, 4) // Array [0, 1, 2, 3]
120+
math.range(0, 4) // Array [0, 1, 2, 3]
121121
122122
// create a new instance of math.js with bignumber configuration
123123
const bigmath = math.create({
124-
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
125-
precision: 32 // 64 by default, only applicable for BigNumbers
124+
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
125+
precision: 32 // 64 by default, only applicable for BigNumbers
126126
})
127127
128128
// parser will parse numbers as BigNumber now:
129-
bigmath.eval('1 / 3') // BigNumber, 0.33333333333333333333333333333333
129+
bigmath.evaluate('1 / 3') // BigNumber, 0.33333333333333333333333333333333
130130
</script>
131131
</body>
132132
</html>

docs/core/extension.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ math.import({
4444
})
4545

4646
// defined functions can be used in both JavaScript as well as the parser
47-
math.myvalue * 2 // 84
48-
math.hello('user') // 'hello, user!'
47+
math.myvalue * 2 // 84
48+
math.hello('user') // 'hello, user!'
4949

5050
const parser = math.parser()
51-
parser.eval('myvalue + 10') // 52
52-
parser.eval('hello("user")') // 'hello, user!'
51+
parser.evaluate('myvalue + 10') // 52
52+
parser.evaluate('hello("user")') // 'hello, user!'
5353
```
5454

5555
## Import external libraries
@@ -72,11 +72,11 @@ math.import(require('numbers'), {wrap: true, silent: true})
7272
math.import(require('numeric'), {wrap: true, silent: true})
7373

7474
// use functions from numbers.js
75-
math.fibonacci(7) // 13
76-
math.eval('fibonacci(7)') // 13
75+
math.fibonacci(7) // 13
76+
math.evaluate('fibonacci(7)') // 13
7777

7878
// use functions from numeric.js
79-
math.eval('eig([1, 2; 4, 3])').lambda.x // [5, -1]
79+
math.evaluate('eig([1, 2; 4, 3])').lambda.x // [5, -1]
8080
```
8181

8282

docs/core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The core of math.js is the `math` namespace containing all functions and constants. There are three ways to do calculations in math.js:
66

77
- Doing regular function calls like `math.add(math.sqrt(4), 2)`.
8-
- Evaluating expressions like `math.eval('sqrt(4) + 2')`
8+
- Evaluating expressions like `math.evaluate('sqrt(4) + 2')`
99
- Chaining operations like `math.chain(4).sqrt().add(2)`.
1010

1111
## Configuration

docs/datatypes/bignumbers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ math.bignumber('2.3e+500') // BigNumber, 2.3e+500
1515
Most functions can determine the type of output from the type of input:
1616
a number as input will return a number as output, a BigNumber as input returns
1717
a BigNumber as output. Functions which cannot determine the type of output
18-
from the input (for example `math.eval`) use the default number type `number`,
18+
from the input (for example `math.evaluate`) use the default number type `number`,
1919
which can be configured when instantiating math.js. To configure the use of
2020
BigNumbers instead of [numbers](numbers.md) by default, configure math.js like:
2121

2222
```js
2323
math.config({
24-
number: 'BigNumber', // Default type of number:
25-
// 'number' (default), 'BigNumber', or 'Fraction'
26-
precision: 64 // Number of significant digits for BigNumbers
24+
number: 'BigNumber', // Default type of number:
25+
// 'number' (default), 'BigNumber', or 'Fraction'
26+
precision: 64 // Number of significant digits for BigNumbers
2727
})
2828

2929
// use math
30-
math.eval('0.1 + 0.2') // BigNumber, 0.3
30+
math.evaluate('0.1 + 0.2') // BigNumber, 0.3
3131
```
3232

3333
The default precision for BigNumber is 64 digits, and can be configured with

docs/datatypes/fractions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ will convert the input to numbers and return a number as result.
3131
Most functions will determine the type of output from the type of input:
3232
a number as input will return a number as output, a Fraction as input returns
3333
a Fraction as output. Functions which cannot determine the type of output
34-
from the input (for example `math.eval`) use the default number type `number`,
34+
from the input (for example `math.evaluate`) use the default number type `number`,
3535
which can be configured when instantiating math.js. To configure the use of
3636
fractions instead of [numbers](numbers.md) by default, configure math.js like:
3737

@@ -42,7 +42,7 @@ math.config({
4242
})
4343

4444
// use the expression parser
45-
math.eval('0.32 + 0.08') // Fraction, 2/5
45+
math.evaluate('0.32 + 0.08') // Fraction, 2/5
4646
```
4747

4848
## Support

docs/datatypes/numbers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Math.js supports three types of numbers:
1414
Most functions can determine the type of output from the type of input:
1515
a number as input will return a number as output, a BigNumber as input returns
1616
a BigNumber as output. Functions which cannot determine the type of output
17-
from the input (for example `math.eval`) use the default number type, which
17+
from the input (for example `math.evaluate`) use the default number type, which
1818
can be configured when instantiating math.js:
1919

2020
```js

docs/datatypes/units.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ Operations with arrays are supported too:
8080

8181
```js
8282
// Force on a charged particle moving through a magnetic field
83-
const B = math.eval('[1, 0, 0] T') // [1 T, 0 T, 0 T]
84-
const v = math.eval('[0, 1, 0] m/s') // [0 m / s, 1 m / s, 0 m / s]
85-
const q = math.eval('1 C') // 1 C
83+
const B = math.evaluate('[1, 0, 0] T') // [1 T, 0 T, 0 T]
84+
const v = math.evaluate('[0, 1, 0] m/s') // [0 m / s, 1 m / s, 0 m / s]
85+
const q = math.evaluate('1 C') // 1 C
8686

8787
const F = math.multiply(q, math.cross(v, B)) // [0 N, 0 N, -1 N]
8888
```
@@ -93,14 +93,14 @@ In general you should avoid calculations using `celsius` and `fahrenheit`. Rathe
9393
This example highlights some problems when using `celsius` and `fahrenheit` in calculations:
9494

9595
```js
96-
const T_14F = math.unit('14 degF') // Unit 14 degF (263.15 K)
97-
const T_28F = math.multiply(T1, 2) // Unit 487.67 degF (526.3 K), not 28 degF
96+
const T_14F = math.unit('14 degF') // Unit 14 degF (263.15 K)
97+
const T_28F = math.multiply(T1, 2) // Unit 487.67 degF (526.3 K), not 28 degF
9898

99-
const Tnegative = math.unit(-13, 'degF') // Unit -13 degF (248.15 K)
100-
const Tpositive = math.abs(T1) // Unit -13 degF (248.15 K), not 13 degF
99+
const Tnegative = math.unit(-13, 'degF') // Unit -13 degF (248.15 K)
100+
const Tpositive = math.abs(T1) // Unit -13 degF (248.15 K), not 13 degF
101101

102-
const Trate1 = math.eval('5 (degC/hour)') // Unit 5 degC/hour
103-
const Trate2 = math.eval('(5 degC)/hour') // Unit 278.15 degC/hour
102+
const Trate1 = math.evaluate('5 (degC/hour)') // Unit 5 degC/hour
103+
const Trate2 = math.evaluate('(5 degC)/hour') // Unit 278.15 degC/hour
104104
```
105105

106106
The expression parser supports units too. This is described in the section about
@@ -112,15 +112,15 @@ You can add your own units to Math.js using the `math.createUnit` function. The
112112

113113
```js
114114
math.createUnit('furlong', '220 yards')
115-
math.eval('1 mile to furlong') // 8 furlong
115+
math.evaluate('1 mile to furlong') // 8 furlong
116116
```
117117

118118
If you cannot express the new unit in terms of any existing unit, then the second argument can be omitted. In this case, a new base unit is created:
119119

120120
```js
121121
// A 'foo' cannot be expressed in terms of any other unit.
122122
math.createUnit('foo')
123-
math.eval('8 foo * 4 feet') // 32 foo feet
123+
math.evaluate('8 foo * 4 feet') // 32 foo feet
124124
```
125125

126126
The second argument to `createUnit` can also be a configuration object consisting of the following properties:
@@ -156,14 +156,14 @@ math.createUnit( {
156156
{
157157
override: true
158158
})
159-
math.eval('50000 kilofoo/s') // 4.5 gigabaz
159+
math.evaluate('50000 kilofoo/s') // 4.5 gigabaz
160160
```
161161

162162
### Return Value
163163
`createUnit` returns the created unit, or, when multiple units are created, the last unit created. Since `createUnit` is also compatible with the expression parser, this allows you to do things like this:
164164

165165
```js
166-
math.eval('45 mile/hour to createUnit("knot", "0.514444m/s")')
166+
math.evaluate('45 mile/hour to createUnit("knot", "0.514444m/s")')
167167
// 39.103964668651976 knot
168168
```
169169

@@ -229,7 +229,7 @@ determine the best fitting prefix for the unit.
229229

230230
## Unit reference
231231

232-
This section lists all available units, prefixes, and physical constants. These can be used via the Unit object, or via `math.eval()`.
232+
This section lists all available units, prefixes, and physical constants. These can be used via the Unit object, or via `math.evaluate()`.
233233

234234
## Reference
235235

0 commit comments

Comments
 (0)