The litecalc library is a lightweight and user-friendly mathematical expressions evaluator, tailored for simple mathematical operations.
To install litecalc, use npm:
npm install litecalc
Litecalc is straightforward to use. After installation, import it and start evaluating expressions.
import { litecalc } from 'litecalc';
// Addition and Subtraction:
litecalc('1 + 1'); // Output: 2
litecalc('3 - 1'); // Output: 2
// Multiplication and Division:
litecalc('2 * 5'); // Output: 10
litecalc('100 / 10'); // Output: 10
// Exponentiation:
litecalc('pow(10, 2)'); // Output: 100
// Constants:
litecalc('pi * 2'); // Output: 6.28...
Litecalc supports the following mathematical functions:
pow(base, exponent)
: Raises a base to the power of an exponent.sqrt(value)
: Calculates the square root of a given value.hypot(...values)
: Computes the square root of the sum of the squares of its arguments.sin(angle)
: Returns the sine of an angle in radians.cos(angle)
: Returns the cosine of an angle in radians.tan(angle)
: Returns the tangent of an angle in radians.
Litecalc includes the following mathematical constants:
pi
: The mathematical constant representing the ratio of a circle's circumference to its diameter.e
: The mathematical constant representing the base of natural logarithms.tau
: The double of the mathematical constant pi, representing one full revolution in radians.
Litecalc includes the following interpreter instructions:
@set
: Use for define constants.@add
: Use for add a value to one constant value.@sub
: Use for subtract a value to one constant value.@remove
: Use for delete a constant.
import { litecalc } from 'litecalc';
litecalc(`
@set(a, 10)
@set(b, 15)
@set(sum, a + b)
@set(a, 15)
@set(b, 30)
@add(sum, a + b)
sum
`); // 70