C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Functions
exprtk_recursive_fibonacci.cpp File Reference
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_recursive_fibonacci.cpp:

Go to the source code of this file.

Functions

template<typename T >
void recursive_fibonacci_example ()
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 74 of file exprtk_recursive_fibonacci.cpp.

75{
76 recursive_fibonacci_example<double>();
77 return 0;
78}

◆ recursive_fibonacci_example()

template<typename T >
void recursive_fibonacci_example ( )

Definition at line 26 of file exprtk_recursive_fibonacci.cpp.

27{
28 typedef exprtk::symbol_table<T> symbol_table_t;
29 typedef exprtk::expression<T> expression_t;
30 typedef exprtk::parser<T> parser_t;
31 typedef exprtk::function_compositor<T> compositor_t;
32 typedef typename compositor_t::function function_t;
33
35
36 symbol_table_t symbol_table;
37
38 symbol_table.add_package(io_package);
39
40 compositor_t compositor(symbol_table);
41
42 compositor.add(
43 function_t("fibonacci")
44 .var("n")
45 .expression
46 ( " (n < 2) ? n : fibonacci(n - 1) + fibonacci(n - 2); " ));
47
48
49 const std::string fibonacci_program =
50 " const var n := 35; "
51 " "
52 " for (var i := 0; i <= n; i += 1) "
53 " { "
54 " var fib_i := fibonacci(i); "
55 " println('fib(',i,') = ', fib_i); "
56 " } ";
57
58 expression_t expression;
59 expression.register_symbol_table(symbol_table);
60
61 parser_t parser;
62 parser.compile(fibonacci_program,expression);
63
64 exprtk::timer timer;
65 timer.start();
66
67 expression.value();
68
69 timer.stop();
70
71 printf("Total time: %8.4fsec\n",timer.time());
72}
double time() const
Definition exprtk.hpp:43502

References exprtk::timer::start(), exprtk::timer::stop(), and exprtk::timer::time().

Here is the call graph for this function: