### 10 unstable releases (3 breaking)

0.4.0 | Jul 22, 2024 |
---|---|

0.3.3 | Jul 3, 2024 |

0.2.2 | Jun 30, 2024 |

0.1.1 | Jun 30, 2024 |

#**155** in Math

**79** downloads per month

**MIT/Apache**

345KB

9K
SLoC

# String Calculator

A small package containing eval methods to compute formulas inside strings.

## How to use

Simply import the eval you need and use it.

`use` `string_calculator``::`eval_f64`;`
`fn` `main``(``)`` ``{`
`println!``(``"``{}``"``,` `eval_f64``(``"`(2+3) / 2`"``.``to_string``(``)``,` `0.``0``)``)``;` `//` 2.5
`}`

## Features

By default, all features are enabled. If you only want a specific eval method, use the feature associated with it's name in the list:

`eval_complex``eval_decimal``eval_f64``eval_i64``eval_number`

Example:

`[``dependencies``]`
`string_calculator = { version = "0.4", default-features = false, features ``=` `[``"`eval_decimal`"``]` }

## Operators

Since there's a lot of things that could be simplified visually, here's the full list of operators implemented.

- Add (x+y)
This operator handle the addition between two number.
Example:
`1``+``2``=``3` - Subtract (x-y)
This operator handle the subtraction between two number.
Example:
`2``-``1``=``1` - Multiply (x*y)
This operator handle the multiplication between two number.
Example:
`3``*``2``=``6` - Divide (x/y)
This operator handle the division between two number.
Example:
`4``/``2``=``2` - Modulo (x%y) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

) This operator handle the rest of the euclidian division between two number. Example:`eval_i64``4``%``2``=``0` - Left Shift (x<<y) (only in

) This operator shift the bits of`eval_i64`

to`x`

positions to the left (it's the same as multiplying by`y`

). Example:`2``^`y`1``<``<``2``=``4` - Right Shift (x>>y) (only in

) This operator shift the bits of`eval_i64`

to`x`

positions to the right (it's the same as dividing by`y`

). Example:`2``^`y`4``>``>``2``=``1` - PowerOf (x^y)
This operator handle the power of

by`x`

,`y`

and`x`

being both numbers. Example:`y``3``^``3``=``27` - Subscript support (x²)
This operator handle the power of

by using the superscript notation (such as`x`

) for integers,`²`

being a number. Example:`x``5`²`=``25` - Factorial (x!) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

) This operator handle the factorial of a real`eval_i64`

. Example:`x``5``!``=``120` - DegToRad (x°) (only in

,`eval_complex`

and`eval_number`

) This operator handle the conversion from degree to radian. You should note that it's priority is the same as multiplication. Example:`eval_f64``3`°`=``0.``05235987755982989` - RadToDeg (x rad) (only in

,`eval_complex`

and`eval_number`

) This operator handle the conversion from radian to degree. You should note that it's priority is the same as multiplication. Example:`eval_f64``3`rad`=``171.``8873385393`

## Constants

- Pi (π) (only in

,`eval_complex`

,`eval_number`

and`eval_decimal`

) Pi is available as`eval_f64`

or`pi`

.`π` - E (e) (only in

,`eval_complex`

,`eval_number`

and`eval_decimal`

) E is available as`eval_f64`

.`e`

## Function notation

Some function can be written purely using their original mathematical notation if wanted.

- Floor (⌊x⌋) (only in

,`eval_f64`

and`eval_number`

) This function gives the greatest integer less than or equal to`eval_decimal`

. Example:`x``⌊``2.``4`⌋`=``2` - Ceiling (⌈x⌉) (only in

,`eval_f64`

and`eval_number`

) This function gives the smallest integer greater or equal to`eval_decimal`

. Example:`x``⌈``2.``4`⌉`=``3`

## Functions

- Absolute value (abs(x))
- Signum (sgn(x), sign(x), signum(x)) (only in

,`eval_decimal`

,`eval_f64`

and`eval_number`

)`eval_i64` - Power (pow(x,y))
- Square root (sqrt(x))
- Root (root(x, n))
- Modulo (mod(x,y)) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

)`eval_i64` - Exponential (exp(x), exp2(x))
- Logarithm (ln(x), lb(x), log(x, b))
- Extremum (min(...X), max(...X)) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

)`eval_i64` - Avg (avg(...X)) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

)`eval_i64` - Median (median(...X), med(...X)) (only in

,`eval_decimal`

,`eval_number`

and`eval_f64`

)`eval_i64` - Truncate (trunc(x), truncate(x)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Floor (floor(x)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Ceil (ceil(x)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Round (round(x)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Lambert W (lambert_w(x), w(x)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Iterated Logarithm (ilog(x, b)) (only in

,`eval_f64`

and`eval_number`

)`eval_decimal` - Sin (sin(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Asin (asin(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - cos (cos(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Acos (acos(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Tan (tan(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Atan (atan(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Sinh (sinh(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Asinh (asinh(x), arsinh(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Cosh (cosh(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Acosh (acosh(x), arcosh(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Tanh (tanh(θ)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Atanh (atanh(x), artanh(x)) (only in

,`eval_complex`

and`eval_number`

)`eval_f64` - Atan 2 (atan2(y, x)) (only in

and`eval_f64`

)`eval_number` - GCD (gcd(...X)) (only in

)`eval_i64` - LCM (lcm(...X)) (only in

)`eval_i64`

## Placeholder Getter

The

symbol is used here as a placeholder for the value you want to put into the `@`

.
In the case you're writting a calculator, it might be useful to use your previous answer for example.`eval_XXXXX`

#### Dependencies

~160KB