+mpdecimal (#70)

This commit is contained in:
Max Howell 2022-08-02 18:24:06 -04:00 committed by GitHub
parent 0f35c7d2be
commit 70d0af6b81
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,21 @@
distributable:
url: https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{{ version }}.tar.gz
strip-components: 1
versions:
- 2.5.1
build:
dependencies:
tea.xyz/gx/cc: c99
tea.xyz/gx/make: '*'
script: |
./configure --prefix={{ prefix }}
make --jobs {{ hw.concurrency }} install
test:
dependencies:
tea.xyz/gx/cc: c99
script: |
cc {{ pkg.pantry-prefix }}/test.c -o test -lmpdec
./test

View file

@ -0,0 +1,22 @@
#include <assert.h>
#include <mpdecimal.h>
#include <string.h>
int main() {
mpd_context_t ctx;
mpd_t *a, *b, *result;
char *rstring;
mpd_defaultcontext(&ctx);
a = mpd_new(&ctx);
b = mpd_new(&ctx);
result = mpd_new(&ctx);
mpd_set_string(a, "0.1", &ctx);
mpd_set_string(b, "0.2", &ctx);
mpd_add(result, a, b, &ctx);
rstring = mpd_to_sci(result, 1);
assert(strcmp(rstring, "0.3") == 0);
mpd_del(a);
mpd_del(b);
mpd_del(result);
mpd_free(rstring);
return 0;
}