Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Created August 18, 2014 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmccarthy/f3136e27daa98668b512 to your computer and use it in GitHub Desktop.
Save ljmccarthy/f3136e27daa98668b512 to your computer and use it in GitHub Desktop.
Compute factorial(1000) with mpdecimal
#include <stdio.h>
#include "mpdecimal.h"
int main()
{
mpd_context_t ctx;
mpd_t *a, *b, *c;
mpd_maxcontext(&ctx);
a = mpd_new(&ctx);
b = mpd_new(&ctx);
c = mpd_new(&ctx);
mpd_set_i32(a, 1, &ctx);
int n = 0;
while (n <= 1000) {
//char *s = mpd_to_sci(a, 1);
//printf("fac(%d) = %s\n", n, s);
//mpd_free(s);
mpd_set_i32(b, ++n, &ctx);
mpd_qmul(c, a, b, &ctx, NULL);
mpd_qcopy(a, c, NULL);
}
mpd_del(a);
mpd_del(b);
mpd_del(c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment