mirror of
https://github.com/zhigang1992/math-literal.git
synced 2026-01-12 08:14:11 +08:00
1.6 KiB
1.6 KiB
Math Literal
Then problem:
BigNumber.add(BigNumber.div(BigNumber.plus(a, BigNumber.times(b, c)), d), e)
This is hard to read, and hard maintain.
npm i math-literal
then
math`(${a} + ${b} * ${c}) / ${d} + ${e}`
mathIs`abs(${a}) > ${b}`
Available Operators
Arithmetic Operators
+: Addition-: Subtraction*orx: Multiplication/: Division**or^: Exponentiation
Special Arithmetic Operators
<<: Left move decimals (equivalent to multiplying by a power of 10)>>: Right move decimals (equivalent to dividing by a power of 10)
Unary Operators
-: Negation (when used before a number or expression)
Functions
round(x): Round to the nearest integerfloor(x): Round down to the nearest integerceil(x): Round up to the nearest integersqrt(x): Square rootabs(x): Absolute valueln(x): Natural logarithmexp(x): Exponential function (e^x)max(x, y): Maximum of two valuesmin(x, y): Minimum of two values
Comparison Operators (for mathIs)
>: Greater than>=: Greater than or equal to<: Less than<=: Less than or equal to===or==: Equal to!==or!=: Not equal to
Logical Operators (for mathIs)
&&: Logical AND||: Logical OR
Grouping
( ): Parentheses for grouping expressions and function arguments
Note: The order of operations follows standard mathematical conventions, with functions and parentheses having the highest precedence, followed by exponents, multiplication/division, and then addition/subtraction.