void test_mpd(void) { mpd_context_t ctx; mpd_t *n; char *sn = NULL; uint32_t res = 0; mpd_maxcontext(&ctx); n = mpd_qnew(); if (!n) { die("Allocating new number failed\n"); } mpd_qset_string(n, NUMBER1, &ctx, &res); sn = mpd_to_sci(n, 0); if (strcmp(sn, NUMBER1) != 0) { die("Failed converting number to string\n"); } free(sn); mpd_del(n); }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *a, *b; mpd_t *q, *r; char *qs, *rs; char status_str[MPD_MAX_FLAG_STRING]; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "divmod: usage: ./divmod x y\n"); exit(1); } mpd_init(&ctx, 38); ctx.traps = 0; q = mpd_new(&ctx); r = mpd_new(&ctx); a = mpd_new(&ctx); b = mpd_new(&ctx); mpd_set_string(a, argv[1], &ctx); mpd_set_string(b, argv[2], &ctx); start_clock = clock(); mpd_divmod(q, r, a, b, &ctx); end_clock = clock(); fprintf(stderr, "time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); qs = mpd_to_sci(q, 1); rs = mpd_to_sci(r, 1); mpd_snprint_flags(status_str, MPD_MAX_FLAG_STRING, ctx.status); printf("%s %s %s\n", qs, rs, status_str); mpd_del(q); mpd_del(r); mpd_del(a); mpd_del(b); mpd_free(qs); mpd_free(rs); return 0; }
void mpd_print(const mpd_t *dec) { char *decstring; decstring = mpd_to_sci(dec, 1); if (decstring != NULL) { printf("%s\n", decstring); mpd_free(decstring); } else { fputs("mpd_fprint: output error\n", stderr); /* GCOV_NOT_REACHED */ } }
/* The following two functions are mainly intended for debugging. */ void mpd_fprint(FILE *file, const mpd_t *dec) { char *decstring; decstring = mpd_to_sci(dec, 1); if (decstring != NULL) { fprintf(file, "%s\n", decstring); mpd_free(decstring); } else { fputs("mpd_fprint: output error\n", file); /* GCOV_NOT_REACHED */ } }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *a, *b; mpd_t *result; char *rstring; char status_str[MPD_MAX_FLAG_STRING]; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "shift: usage: ./shift x y\n"); exit(1); } mpd_init(&ctx, 38); ctx.traps = 0; result = mpd_new(&ctx); a = mpd_new(&ctx); b = mpd_new(&ctx); mpd_set_string(a, argv[1], &ctx); mpd_set_string(b, argv[2], &ctx); start_clock = clock(); mpd_shift(result, a, b, &ctx); end_clock = clock(); fprintf(stderr, "time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); rstring = mpd_to_sci(result, 1); mpd_snprint_flags(status_str, MPD_MAX_FLAG_STRING, ctx.status); printf("%s %s\n", rstring, status_str); mpd_del(a); mpd_del(b); mpd_del(result); mpd_free(rstring); return 0; }
void EigenLib_cplx_mpType_Print(const char * Title, mpCplxMatrixPtr xPtr) { int mRows = xPtr->rows(); int mCols = xPtr->cols(); cplx_mpType x; printf ("\n"); printf (Title); printf ("\n"); #if defined (Use_Mpfi) mpfr_t real_fL; mpfr_init(real_fL); mpfr_t real_fR; mpfr_init(real_fR); mpfr_t imag_fL; mpfr_init(imag_fL); mpfr_t imag_fR; mpfr_init(imag_fR); #endif // defined (Use_Mpfi) for (int i=1; i<=mRows; i++) { for (int j=1; j<=mCols; j++) { EigenLib_cplx_mpType_GetCoeff(&x, i-1, j-1, xPtr); #if defined (Use_Float) __mingw_printf("(%.8E,%.8E) ", real(x), imag(x)); #endif #if defined (Use_Double) __mingw_printf("(%.16E,%.16E) ", real(x), imag(x)); #endif #if defined (Use_LongDouble) __mingw_printf("(%.20LE,%.20LE) ", real(x), imag(x)); #endif #if defined (Use_Mpfr) mpfr_printf("(%.RE,%.RE) ", real(x).mpfr_ptr(), imag(x).mpfr_ptr()); #endif #if defined (Use_Mpfi) mpfi_get_left(real_fL, real(x).mpfi_ptr()); mpfi_get_right(real_fR, real(x).mpfi_ptr()); mpfi_get_left(imag_fL, imag(x).mpfi_ptr()); mpfi_get_right(imag_fR, imag(x).mpfi_ptr()); mpfr_printf("([%.RE,%.RE] [%.RE,%.RE]) ", real_fL, real_fR, imag_fL, imag_fR); #endif #if defined (Use_Mpdec) char *s1 = mpd_to_sci(real(x).mpd_ptr(), 1); char *s2 = mpd_to_sci(imag(x).mpd_ptr(), 1); printf("(%s,%s)", s1, s2); mpd_free(s1); mpd_free(s2); #endif } printf("\n"); } #if defined (Use_Mpfi) mpfr_clear(real_fL); mpfr_clear(real_fR); mpfr_clear(imag_fL); mpfr_clear(imag_fR); #endif // defined (Use_Mpfi) }