rcalc_lib/
lib.rs

1//! # Expression calculator
2//!
3//! Calculator transparently supports operations with different type of numbers,
4//! converting to appropriate type when it is needed. For instance,
5//! `sqrt(-2)` is automatically converted from integer number `-2` to complex
6//! one `-2+0i` and is evaluated to `0+1.4142135623730951i`
7//!
8//! Extra feature: trigonometric functions support both radians and degrees:
9//! * Radians are just float numbers: `sin(pi/2)` returns `1`
10//! * Degrees can be written in one of the following forms: `12°30'45"` or `12d30m45s` or `12.5125d`
11//!
12//! Internally degrees are stored and act as float numbers. They only support
13//! their own input format. Output format is always a float number.
14//!
15//! If two numbers have different types, they are converted to highest type and
16//! then the result is calculated. The list of number types starting from highest:
17//! * Complex numbers. Two input formats supported: `1+2i` and `1+i2`. `i` can be capital. `j` can
18//! be used instead of `i`
19//! * Float numbers (degrees are float numbers, too)
20//! * Rational numbers
21//! * Big integer numbers
22//!
23//! Note: sometimes higher types are converted to lower ones. It may happen
24//! after multiplication, division, and squaring a number. Examples:
25//! * `sqr(0+2i)` -> `-4` - automatically complex is converted to float number
26//! * `1.5 / 0.5` -> `3` - float to big integer
27//! * `1\2 + 1\2` -> `1` - half and half is an integer one
28//!
29//! The list of supported functions:
30//! * trigonometric functions (including inverted ones): sin, cos, tan, asin, acos, atan
31//! * hyperbolic functions (including inverted ones): sinh, cosh, tanh, asinh, acosh, atanh
32//! * square and square root: sqr and sqrt
33//! * exponent, logarithm: exp, ln
34//! * complex functions: norm, re, im, conjugate
35//! * rounding: ceil, floor, trunc, round
36//! * float to rational: ratio
37//! * absolute value and sign: abs, signum
38//! * fractional part of a float number: fract
39//!
40//! Operators (starting from highest priority):
41//! * `!` - factorial (when used after a number or closing bracket)
42//! * `-` - unary minus
43//! * `**` - power
44//! * `*`, `/`, `//` - multiplication, division, integer division
45//! * `+`, `-` - addition, subtraction
46//! * `&`, `^` - bitwise AND and XOR
47//! * `|`, `<<`, `>>` - bitwise OR, SHL, and SHR
48//! * `==`, `!=`, `>`, `<`, `>=`, and `<=` - comparison operators
49//!
50//! Predefined constants:
51//! * `PI` - 3.14159...
52//! * `E` - 2.71828...
53//! * `PHI` - golden section - 1.6180...
54//!
55//! The calculator does not have special type for boolean numbers. When using logical
56//! operators any zero value is treated as `false` and `true` otherwise. So, doing
57//! double NOT transforms any number into big integer `1` or `0` depending on if the
58//! original value was zero
59
60#[macro_use]
61extern crate pest_derive;
62
63pub mod errors;
64pub mod parse;
65pub mod stack;
66pub mod value;