2.0.14 • Published 3 years ago
@algorithm.ts/calculate v2.0.14
A tiny calculator for number arithmetics such as +-*/()
.
Install
npm
npm install --save @algorithm.ts/calculate
yarn
yarn add @algorithm.ts/calculate
deno
import calculate from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/calculate/src/index.ts'
Usage
// Perform integer arithmetics.
import calculate from 'algorithm.ts/calculate'
// or
import { calculate } from 'algorithm.ts/calculate'
// Perform decimal arithmetics.
import { decimalCalculate } from 'algorithm.ts/calculate'
// Perform bigint arithmetics.
import { bigintCalculate } from 'algorithm.ts/calculate'
Examples
integer arithmetics
import calculate from '@algorithm.ts/calculate' calculate('3/2') // => 1 calculate('-2+1') // => -1 calculate('-2*3 + 2*5*3/6') // => -1 calculate('(1+(4+5+2)-3)+(6+8)') // => 23
decimal arithmetics
import { decimalCalculate as calculate } from '@algorithm.ts/calculate' calculate('3/2') // => 1.5 calculate('-2+1') // => -1 calculate('-2*3 + 2*5*3/6') // => -1 calculate('(1+(4+5+2)-3)+(6+8)') // => 23
bigint arithmetics
import { bigintCalculate as calculate } from '@algorithm.ts/calculate' calculate('22222222222222222222222222222 * 3333333333333333333323232') // => 74074074074074074073849599999259259259259259259261504n
Illegal inputs
import calculate from '@algorithm.ts/calculate' calculate('-2++1') // => SyntaxError calculate('-2*/23') // => SyntaxError calculate('1+(4+5+2))') // => SyntaxError calculate('1+(4+5+2') // => SyntaxError
A solution of https://leetcode.com/problems/basic-calculator/
export { calculate } from '@algorithm.ts/calculate'
A solution of https://leetcode.com/problems/basic-calculator-ii/
export { calculate } from '@algorithm.ts/calculate'
Related
2.0.14
3 years ago
2.0.13
3 years ago
2.0.12
3 years ago
2.0.5
3 years ago
2.0.4
3 years ago
2.0.11
3 years ago
2.0.7
3 years ago
2.0.6
3 years ago
2.0.9
3 years ago
2.0.10
3 years ago
2.0.8
3 years ago
2.0.8-alpha.0
3 years ago
2.0.7-alpha.1
3 years ago
2.0.7-alpha.0
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.0-alpha.0
3 years ago
2.0.1
3 years ago
1.0.24
3 years ago
2.0.0
3 years ago
1.0.23
4 years ago
1.0.19
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.20
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago