本文整理汇总了C++中SymEngine::real_double方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::real_double方法的具体用法?C++ SymEngine::real_double怎么用?C++ SymEngine::real_double使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::real_double方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: R7
double R7()
{
RCP<const Basic> x = symbol("x");
RCP<const Basic> f = add(pow(x, integer(24)),
add(mul(integer(34), pow(x, integer(12))),
add(mul(integer(45), pow(x, integer(3))),
add(mul(integer(9), pow(x, integer(18))),
add(mul(integer(34), pow(x, integer(10))),
mul(integer(32), pow(x, integer(21))))))));
vec_basic v;
auto t1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 10000; ++i) {
v.push_back(f->subs({{x, real_double(0.5)}}));
}
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
示例2: symbol
using SymEngine::integer;
using SymEngine::real_double;
using SymEngine::complex_double;
using SymEngine::sin;
using SymEngine::pi;
TEST_CASE("Constructors of Expression", "[Expression]")
{
Expression e0 = symbol("x");
REQUIRE(eq(*e0.get_basic(), *symbol("x")));
Expression e1 = 20;
REQUIRE(eq(*e1.get_basic(), *integer(20)));
Expression e2 = 10.0;
REQUIRE(eq(*e2.get_basic(), *real_double(10.0)));
Expression e3 = std::complex<double>(1.0, 2.0);
REQUIRE(
eq(*e3.get_basic(), *complex_double(std::complex<double>(1.0, 2.0))));
}
TEST_CASE("Printing of Expression", "[Expression]")
{
Expression e0 = symbol("x");
std::stringstream s;
s << e0;
REQUIRE(s.str() == "x");
}
TEST_CASE("Arithmetic of Expression", "[Expression]")
示例3: add
5.773239267559},
{sub(add(add(asinh(r4), add(acosh(r4), add(atanh(r3), acoth(r4)))),
sech(r4)),
acsch(r4)),
4.825120290814},
{SymEngine::abs(log(div(pi, mul(E, integer(2))))), 0.548417294710},
{SymEngine::atan2(r1, neg(r2)), 2.08867384922582},
{mul(pi, mul(E, EulerGamma)), 4.92926836742289},
{pow(mul(EulerGamma, r4), integer(8)), 4813.54354505117582},
{mul(EulerGamma, integer(10)), 5.7721566490153286},
{max({r2, r1}), 0.841470984808},
{min({add(r1, r4), r2}), 0.479425538604},
{gamma(div(integer(4), integer(3))), 0.892979511569249211},
{loggamma(div(integer(7), integer(2))), 1.200973602347074224},
{loggamma(pi), 0.82769459232343710152},
{add(asech(div(one, integer(2))), real_double(0.1)), 1.41695789692482},
{r5, 0.841470984807897},
};
for (unsigned i = 0; i < vec.size(); i++) {
double val = eval_double(*vec[i].first);
std::cout.precision(12);
std::cout << vec[i].first->__str__() << " ~ " << val << std::endl;
REQUIRE(::fabs(val - vec[i].second) < 1e-12);
}
for (unsigned i = 0; i < vec.size(); i++) {
double val = eval_double_single_dispatch(*vec[i].first);
REQUIRE(::fabs(val - vec[i].second) < 1e-12);
}
示例4: add
r1 = add(pow(x, y), z);
r2 = add(z, pow(x, y));
REQUIRE(eq(*r1, *r2));
r1 = add(x, I);
r2 = add(I, x);
REQUIRE(eq(*r1, *r2));
r1 = mul(x, I);
r2 = mul(mul(I, i2), x);
r3 = mul(mul(I, i3), x);
r2 = add(r1, r2);
REQUIRE(eq(*r3, *r2));
r1 = real_double(0.1);
r2 = Rational::from_mpq(mpq_class(1, 2));
r3 = add(add(add(r1, r2), integer(1)), real_double(0.2));
REQUIRE(is_a<RealDouble>(*r3));
REQUIRE(std::abs(rcp_static_cast<const RealDouble>(r3)->i - 1.8) < 1e-12);
r1 = complex_double(std::complex<double>(0.1, 0.2));
r2 = Complex::from_two_nums(*Rational::from_mpq(mpq_class(1, 2)), *Rational::from_mpq(mpq_class(7, 5)));
r3 = add(add(add(r1, r2), integer(1)), real_double(0.4));
REQUIRE(is_a<ComplexDouble>(*r3));
REQUIRE(std::abs(rcp_static_cast<const ComplexDouble>(r3)->i.real() - 2.0) < 1e-12);
REQUIRE(std::abs(rcp_static_cast<const ComplexDouble>(r3)->i.imag() - 1.6) < 1e-12);
}
TEST_CASE("Mul: arit", "[arit]")
{
示例5: a
mpfr_class a(100), b(100), d(100), c(100);
mpfr_set_ui(a.get_mpfr_t(), 10, MPFR_RNDN);
mpfr_set_ui(b.get_mpfr_t(), 20, MPFR_RNDN);
mpfr_set_ui(c.get_mpfr_t(), 100, MPFR_RNDN);
mpfr_set_ui(d.get_mpfr_t(), 1024, MPFR_RNDN);
RCP<const Number> r1 = real_mpfr(std::move(a));
RCP<const Number> r2 = real_mpfr(std::move(b));
RCP<const Number> r3 = real_mpfr(std::move(c));
RCP<const Number> r4 = real_mpfr(std::move(d));
RCP<const Number> r5 = subnum(integer(0), r1);
RCP<const Number> i1 = integer(1);
RCP<const Number> i2 = integer(2);
RCP<const Number> half = integer(1)->div(*integer(2));
RCP<const Number> c1 = Complex::from_two_nums(*i1, *i1);
RCP<const Number> rat1 = Rational::from_two_ints(*integer(10), *integer(3));
RCP<const Number> rd1 = real_double(10.0);
RCP<const Number> cd1 = complex_double(std::complex<double>(1, 2));
REQUIRE(not r1->is_one());
REQUIRE(not r1->is_minus_one());
REQUIRE(not r1->is_complex());
REQUIRE(eq(*r2, *addnum(r1, r1)));
REQUIRE(is_a<RealMPFR>(*addnum(r1, rat1)));
REQUIRE(eq(*r2, *addnum(r1, rd1)));
REQUIRE(eq(*r1, *subnum(r1, integer(0))));
REQUIRE(is_a<RealMPFR>(*subnum(r2, rat1)));
REQUIRE(eq(*r1, *subnum(r2, rd1)));
REQUIRE(is_a<RealMPFR>(*subnum(rat1, r2)));
REQUIRE(eq(*neg(r1), *subnum(rd1, r2)));
REQUIRE(eq(*r2, *mulnum(r1, i2)));