/*
**************************************************************
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 09 *
* Author: Arash Partow (1999-2025) *
* URL: https://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *
* Free use of the Mathematical Expression Toolkit Library is *
* permitted under the guidelines and in accordance with the *
* most current version of the MIT License. *
* https://www.opensource.org/licenses/MIT *
* SPDX-License-Identifier: MIT *
* *
**************************************************************
*/
#include
#include
#include "exprtk.hpp"
template
void primes()
{
typedef exprtk::symbol_table symbol_table_t;
typedef exprtk::expression expression_t;
typedef exprtk::parser parser_t;
typedef exprtk::function_compositor compositor_t;
typedef typename compositor_t::function function_t;
T x = T(0);
symbol_table_t symbol_table;
symbol_table.add_constants();
symbol_table.add_variable("x",x);
compositor_t compositor(symbol_table);
//Mode 1 - if statement based
compositor.add(
function_t("is_prime_impl1")
.vars("x", "y")
.expression
(
" if (y == 1,true, "
" if (0 == (x % y),false, "
" is_prime_impl1(x,y - 1))) "
));
compositor.add(
function_t("is_prime1")
.var("x")
.expression
(
" if (frac(x) != 0) "
" return [false]; "
" else if (x