Skip to content

Math.js: Core Syntax & Numbers

JS Calc utilizes Math.js for a wide array of numerical calculations, expression parsing, and operations involving units, matrices, and complex numbers. This section covers the fundamental syntax and number types you can use.

Arithmetic Operators

Standard arithmetic operations are supported as you would expect:

Operator Description Example Result
+ Addition 2 + 3 5
- Subtraction 5 - 2 3
* Multiplication 3 * 4 12
.* Element-wise multiply [1,2,3] .* [1,2,3] [1,4,9]
/ Division 10 / 2 5
./ Element-wise divide [9,6,4] ./ [3,2,2] [3,3,2]
^ Power 2^3 8
.^ Element-wise power [2,3] .^ [3,3] [8,27]
% mod Modulus 10 % 3 1
' Transpose [[1,2],[3,4]]' [[1,3],[2,4]]
! Factorial 5! 120
() Grouping (2 + 3) * 4 20

Operator precedence follows standard mathematical rules (PEMDAS/BODMAS). Parentheses () can be used to explicitly control the order of operations.

Note: Arithmetic operations also work seamlessly with physical units. For more details, see the Units and Conversions section.

Numbers

JS Calc supports various number formats:

Integers

Whole numbers, both positive and negative. 123, -5

Decimals

Floating-Point Numbers 3.14, -0.01

Scientific Notation:

2e3 = 2000
1.5e-6 = 0.0000015
5.2E+8 = 520000000