本文整理汇总了C++中SymEngine::eval_double方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::eval_double方法的具体用法?C++ SymEngine::eval_double怎么用?C++ SymEngine::eval_double使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::eval_double方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
SymEngine::print_stack_on_segfault();
RCP<const Basic> e = sin(integer(1));
double r, r_exact;
for (int i = 0; i < 10000; i++)
e = pow(add(mul(add(e, pow(integer(2), integer(-3))), integer(3)),
integer(1)),
div(integer(2), integer(3)));
// Too long:
// std::cout << "Evaluating: " << *e << std::endl;
auto t1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 500; i++)
r = eval_double(*e);
auto t2 = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
.count()
/ 500.
<< "ms" << std::endl;
/*
In SymPy for few iterations:
In [7]: sympify("(1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1
+ 3*(1/8 + sin(1)))^(2/3)))^(2/3)))^(2/3)))^(2/3)))^(2/3)").n(20)
Out[7]: 8.0152751504518535013
// r_exact = 8.0152751504518535013;
Here is code to use SymPy for more iterations:
In [5]: e = sin(1)
In [6]: for i in range(10):
...: e = ((e+2**(-S(3)))*3 + 1)**(S(2)/3)
...:
In [7]: e.n(20)
Out[7]: 9.6473976427977306146
But unfortunately SymPy can't do more than perhaps 10 or 20 iterations,
while
we need to test ~10000. However, the numbers seem to converge to 9.85647...
*/
r_exact = 9.8564741713701043569;
std::cout << "r (double) = " << r << std::endl;
std::cout << "r (exact) = " << r_exact << std::endl;
std::cout << "error = " << std::abs(r - r_exact) << std::endl;
return 0;
}