MCPcopy Create free account
hub / github.com/ArashPartow/exprtk / primes

Function primes

exprtk_simple_example_09.cpp:27–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26template <typename T>
27void primes()
28{
29 typedef exprtk::symbol_table<T> symbol_table_t;
30 typedef exprtk::expression<T> expression_t;
31 typedef exprtk::parser<T> parser_t;
32 typedef exprtk::function_compositor<T> compositor_t;
33 typedef typename compositor_t::function function_t;
34
35 T x = T(0);
36
37 symbol_table_t symbol_table;
38
39 symbol_table.add_constants();
40 symbol_table.add_variable("x",x);
41
42 compositor_t compositor(symbol_table);
43
44 //Mode 1 - if statement based
45 compositor.add(
46 function_t("is_prime_impl1")
47 .vars("x", "y")
48 .expression
49 (
50 " if (y == 1,true, "
51 " if (0 == (x % y),false, "
52 " is_prime_impl1(x,y - 1))) "
53 ));
54
55 compositor.add(
56 function_t("is_prime1")
57 .var("x")
58 .expression
59 (
60 " if (frac(x) != 0) "
61 " return [false]; "
62 " else if (x <= 0) "
63 " return [false]; "
64 " else "
65 " is_prime_impl1(x,min(x - 1,trunc(sqrt(x)) + 1)); "
66 ));
67
68 //Mode 2 - switch statement based
69 compositor.add(
70 function_t("is_prime_impl2")
71 .vars("x", "y")
72 .expression
73 (
74 " switch "
75 " { "
76 " case y == 1 : true; "
77 " case (x % y) == 0 : false; "
78 " default : is_prime_impl2(x,y - 1); "
79 " } "
80 ));
81
82 compositor.add(
83 function_t("is_prime2")
84 .var("x")

Callers

nothing calls this directly

Calls 1

valueMethod · 0.45

Tested by

no test coverage detected