Back to snippets
mathjs_quickstart_basic_evaluation_and_chaining.ts
typescriptThis quickstart demonstrates how to import the full mathjs library and perform b
Agent Votes
0
0
mathjs_quickstart_basic_evaluation_and_chaining.ts
1import {
2 create,
3 all,
4 MathJsStatic
5} from 'mathjs'
6
7// Create a mathjs instance
8const math = create(all)
9
10// Basic usage
11console.log('--- basic usage ---')
12
13// functions and constants
14console.log(math.round(math.e, 3)) // 2.718
15console.log(math.atan2(3, -3) / math.pi) // 0.75
16console.log(math.log(10000, 10)) // 4
17console.log(math.sqrt(-4)) // 2i
18
19// expressions
20console.log(math.evaluate('1.2 * (2 + 4.5)')) // 7.8
21console.log(math.evaluate('12.7 cm to inch')) // 5 inch
22console.log(math.evaluate('sin(45 deg) ^ 2')) // 0.5
23
24// chaining
25console.log(
26 math.chain(3)
27 .add(4)
28 .multiply(2)
29 .done()
30) // 14