1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//#![warn(missing_docs)]
//! Yarer (Yet another (Rusty || Rpn) expression resolver) is a flexible library, written in Rust, for the processing, compilation and evaluation of mathematical expressions using Reverse Polish Notation.
//!
//! # Example of usage of the library:
//!
//! ```
//! use yarer::{rpn_resolver::RpnResolver, session::Session, token::Number};
//!
//! let exp = "((10 + 5) - 3 * ( 9 / 3 )) + 2";
//! let session = Session::init();
//! let mut resolver: RpnResolver = session.process(&exp);
//!
//! let result: Number = resolver.resolve().unwrap();
//! println!("The result of {} is {}", exp, result);
//! ```
//!
//! All that's needed is to create a new instance of the [`RpnResolver`] and hand over the expression to be analysed.
//! The library just returns a variant natural number, or a decimal number if one exists in the expression (i.e '2.1+1') or there's a trigonometric function (i.e. 1/cos(x+1)).
//!
//! Yarer can handle also variables and functions. Here an example:
//!
//! ```
//! # use yarer::{rpn_resolver::RpnResolver, session::Session};
//!
//! let session: Session = Session::init();
//! let mut resolver: RpnResolver = session.process("1/cos(x^2)");
//! session.set("x",1);
//!
//! println!("The result is {}", resolver.resolve().unwrap());
//! ```
//!
//! and of course, the expression can be re-evaluated if the variable changes.
//!
//! ```
//! # use yarer::{rpn_resolver::RpnResolver, session::Session};
//! # let session: Session = Session::init();
//! # let mut resolver: RpnResolver = session.process("1/cos(x^2)");
//!
//! session.set("x",-1);
//! println!("The result is {}", resolver.resolve().unwrap());
//!
//! session.setf("x",0.001);
//! println!("The result is {}", resolver.resolve().unwrap());
//! ```
//!
//! The result can be simply converted into a i32 or a f64 (if decimal) simply with
//!
//! ```
//! # use yarer::{rpn_resolver::RpnResolver, session::Session, token::Number};
//! # let session: Session = Session::init();
//! # let mut resolver: RpnResolver = session.process("1/cos(x^2)");
//!
//! let result: Number = resolver.resolve().unwrap();
//!
//! let int : i32 = result.clone().try_into().unwrap();
//! // or
//! let float : f64 = result.try_into().unwrap();
//! ```
//!
//! Yarer can be used also from command line, and behaves in a very similar manner to GNU bc
//!
//! ```ignore
//! $ yarer
//! Yarer v.0.1.1 - Yet Another (Rusty||Rpn) Expression Resolver.
//! License MIT OR Apache-2.0
//! > (1+9)*(8+2)
//! 100
//! > (1./2)+atan(10)
//! 1.1483608274590869
//! > x=10
//! > 3/sin(5*x^2)
//! -6.41338354698791
//! > ln(1)
//! 0
//! > log(10)
//! 1
//! > -2^-2
//! 0.25
//! > 1/(log(10)+cos(0))^-2
//! 4
//! > 4.5+7.9*2.2
//! 21.88
//! > 9801/(2206*sqrt(2)) // approx of PI
//! 3.1415927300133055
//!
//! ```
//!
//! ## Built-in Defined Functions
//!
//! There are several math functions defined that you can use in your expression. More to come!
//! There are many examples of processed expressions in the [integration test file](https://github.com/davassi/yarer/blob/master/tests/integration_tests.rs)
//!
//! ```ignore
//! Sin
//! Cos
//! Tan
//! ASin
//! ACos
//! ATan
//! Ln
//! Log
//! Abs
//! Sqrt
//! Max
//! Min
//! Floor
//! Ceil
//! Round
//! Exp
//! Pdf
//! Cdf
//! ```
/// Parser
/// `RpnResolver`
/// Session
/// Token