diff --git a/Aliases/libmpdec b/Aliases/libmpdec new file mode 120000 index 00000000000..2437d2f95be --- /dev/null +++ b/Aliases/libmpdec @@ -0,0 +1 @@ +../Formula/mpdecimal.rb \ No newline at end of file diff --git a/Formula/mpdecimal.rb b/Formula/mpdecimal.rb new file mode 100644 index 00000000000..076f75e6965 --- /dev/null +++ b/Formula/mpdecimal.rb @@ -0,0 +1,49 @@ +class Mpdecimal < Formula + desc "Library for decimal floating point arithmetic" + homepage "https://www.bytereef.org/mpdecimal/" + url "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.0.tar.gz" + sha256 "15417edc8e12a57d1d9d75fa7e3f22b158a3b98f44db9d694cfd2acde8dfa0ca" + license "BSD-2-Clause" + + def install + system "./configure", "--prefix=#{prefix}" + system "make" + system "make", "install" + end + + test do + (testpath/"test.c").write <<~EOS + #include + #include + #include + + 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; + } + EOS + system ENV.cc, "test.c", "-o", "test", "-L#{lib}", "-lmpdec" + system "./test" + end +end