using SymEngine::mul; using SymEngine::erf; using SymEngine::sub; using SymEngine::eval_mpfr; using SymEngine::integer_class; using SymEngine::print_stack_on_segfault; using SymEngine::max; using SymEngine::min; using SymEngine::loggamma; TEST_CASE("precision: eval_mpfr", "[eval_mpfr]") { mpfr_t a; mpfr_init2(a, 53); RCP<const Basic> s = mul(pi, integer(1963319607)); RCP<const Basic> t = integer(integer_class("6167950454")); RCP<const Basic> r = sub(s, t); // value of `r` is approximately 0.000000000149734291 eval_mpfr(a, *r, MPFR_RNDN); // `eval_mpfr` was done with a precision of 53 bits (precision of `a`) and // rounding mode `MPFR_RNDN` // With 53 bit precision, `s` and `t` have the same value. // Hence value of `r` was rounded down to `0.000000000000000` REQUIRE(mpfr_cmp_si(a, 0) == 0); mpfr_set_prec(a, 100); eval_mpfr(a, *r, MPFR_RNDN); // `eval_mpfr` was done with a precision of 100 bits (precision of `a`) and // rounding mode `MPFR_RNDN` // With 100 bit precision, `s` and `t` are not equal in value.
// undefined behaviour for C++ standard /*REQUIRE((integer_class(-1024) << 3) == -8192); REQUIRE((integer_class(-1024) >> 3) == -128); REQUIRE((integer_class(-768) << 5) == -24576); REQUIRE((integer_class(-768) >> 5) == -24); REQUIRE((integer_class(-500) << 3) == -4000); REQUIRE((integer_class(-500) >> 3) == -63); REQUIRE((integer_class(-5) << 1) == -10); REQUIRE((integer_class(-5) >> 1) == -3); REQUIRE((integer_class(-4) << 0) == -4); REQUIRE((integer_class(-4) >> 0) == -4); REQUIRE((integer_class(-2) << 10) == -2048); REQUIRE((integer_class(-2) >> 10) == -1); REQUIRE((integer_class(-1) << 4) == -16); REQUIRE((integer_class(-1) >> 4) == -1);*/ REQUIRE((integer_class(0) << 5) == 0); REQUIRE((integer_class(0) >> 5) == 0); REQUIRE((integer_class(1) << 2) == 4); REQUIRE((integer_class(1) >> 2) == 0); REQUIRE((integer_class(2) << 4) == 32); REQUIRE((integer_class(2) >> 4) == 0); REQUIRE((integer_class(4) << 1) == 8); REQUIRE((integer_class(4) >> 1) == 2); REQUIRE((integer_class(5) << 6) == 320); REQUIRE((integer_class(5) >> 6) == 0); REQUIRE((integer_class(500) << 1) == 1000); REQUIRE((integer_class(500) >> 1) == 250); REQUIRE((integer_class(768) << 2) == 3072); REQUIRE((integer_class(768) >> 2) == 192); REQUIRE((integer_class(1024) << 3) == 8192); REQUIRE((integer_class(1024) >> 3) == 128);
CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s, const mpz_t i) { CWRAPPER_BEGIN s->m = SymEngine::integer(integer_class(i)); CWRAPPER_END }
CWRAPPER_OUTPUT_TYPE integer_set_str(basic s, const char *c) { CWRAPPER_BEGIN s->m = SymEngine::integer(integer_class(c)); CWRAPPER_END }
CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s, unsigned long i) { CWRAPPER_BEGIN s->m = SymEngine::integer(integer_class(i)); CWRAPPER_END }