C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
af8fd04155
commit
d068f6e14b
|
@ -25,6 +25,7 @@ template <typename T>
|
||||||
void polynomial()
|
void polynomial()
|
||||||
{
|
{
|
||||||
std::string expression_string = "25x^5 - 35x^4 - 15x^3 + 40x^2 - 15x + 1";
|
std::string expression_string = "25x^5 - 35x^4 - 15x^3 + 40x^2 - 15x + 1";
|
||||||
|
|
||||||
T r0 = T(0);
|
T r0 = T(0);
|
||||||
T r1 = T(1);
|
T r1 = T(1);
|
||||||
T x = T(0);
|
T x = T(0);
|
||||||
|
@ -39,6 +40,7 @@ void polynomial()
|
||||||
parser.compile(expression_string,expression);
|
parser.compile(expression_string,expression);
|
||||||
|
|
||||||
const T delta = T(1.0 / 100.0);
|
const T delta = T(1.0 / 100.0);
|
||||||
|
|
||||||
for (x = r0; x <= r1; x += delta)
|
for (x = r0; x <= r1; x += delta)
|
||||||
{
|
{
|
||||||
printf("%19.15f\t%19.15f\n",x,expression.value());
|
printf("%19.15f\t%19.15f\n",x,expression.value());
|
||||||
|
|
|
@ -69,7 +69,9 @@ void fibonacci()
|
||||||
for (std::size_t i = 0; i < 40; ++i)
|
for (std::size_t i = 0; i < 40; ++i)
|
||||||
{
|
{
|
||||||
x = i;
|
x = i;
|
||||||
|
|
||||||
T result = expression.value();
|
T result = expression.value();
|
||||||
|
|
||||||
printf("fibonacci(%3d) = %10.0f\n",
|
printf("fibonacci(%3d) = %10.0f\n",
|
||||||
static_cast<int>(i),
|
static_cast<int>(i),
|
||||||
result);
|
result);
|
||||||
|
|
|
@ -66,6 +66,7 @@ void composite()
|
||||||
error.diagnostic.c_str(),
|
error.diagnostic.c_str(),
|
||||||
expression_string.c_str());
|
expression_string.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,11 @@ void primes()
|
||||||
for (std::size_t i = 0; i < 100; ++i)
|
for (std::size_t i = 0; i < 100; ++i)
|
||||||
{
|
{
|
||||||
x = i;
|
x = i;
|
||||||
|
|
||||||
T result1 = expression1.value();
|
T result1 = expression1.value();
|
||||||
T result2 = expression2.value();
|
T result2 = expression2.value();
|
||||||
T result3 = expression3.value();
|
T result3 = expression3.value();
|
||||||
|
|
||||||
printf("%03d Result1: %c Result2: %c Result3: %c\n",
|
printf("%03d Result1: %c Result2: %c Result3: %c\n",
|
||||||
static_cast<unsigned int>(i),
|
static_cast<unsigned int>(i),
|
||||||
(result1 == T(1)) ? 'T' : 'F',
|
(result1 == T(1)) ? 'T' : 'F',
|
||||||
|
|
Loading…
Reference in New Issue