89 lines
2.4 KiB
Ruby
89 lines
2.4 KiB
Ruby
class Flint < Formula
|
|
desc "C library for number theory"
|
|
homepage "https://flintlib.org"
|
|
url "https://flintlib.org/flint-2.7.1.tar.gz"
|
|
sha256 "186e2fd9ab67df8a05b122fb018269b382e4babcdb17353c4be1fe364dca481e"
|
|
license "LGPL-2.1-or-later"
|
|
head "https://github.com/wbhart/flint2.git", branch: "trunk"
|
|
|
|
bottle do
|
|
sha256 arm64_big_sur: "68bd7a3053ac5e8363ca0128fea147a9866ae9d6af31a0b2876cb29f9f5b96a3"
|
|
sha256 big_sur: "c49c7f2e195411a78c7e6d0b29dc2b532be8f501158d53b0c5f32bf270e20794"
|
|
sha256 catalina: "09ed48e46ae65d153f1c0014dac7b83436280a7a236bd305b8e82c86762d7777"
|
|
sha256 mojave: "f41f76595678bd2f16dc46ceeb1524c089b931f9f65fe6c826272ce703d36283"
|
|
end
|
|
|
|
depends_on "gmp"
|
|
depends_on "mpfr"
|
|
depends_on "ntl"
|
|
|
|
def install
|
|
ENV.cxx11
|
|
args = %W[
|
|
--with-gmp=#{Formula["gmp"].prefix}
|
|
--with-mpfr=#{Formula["mpfr"].prefix}
|
|
--with-ntl=#{Formula["ntl"].prefix}
|
|
--prefix=#{prefix}
|
|
]
|
|
system "./configure", *args
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
test do
|
|
(testpath/"test.c").write <<-EOS
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "flint.h"
|
|
#include "fmpz.h"
|
|
#include "ulong_extras.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
slong i, bit_bound;
|
|
mp_limb_t prime, res;
|
|
fmpz_t x, y, prod;
|
|
|
|
if (argc != 2)
|
|
{
|
|
flint_printf("Syntax: crt <integer>\\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
fmpz_init(x);
|
|
fmpz_init(y);
|
|
fmpz_init(prod);
|
|
|
|
fmpz_set_str(x, argv[1], 10);
|
|
bit_bound = fmpz_bits(x) + 2;
|
|
|
|
fmpz_zero(y);
|
|
fmpz_one(prod);
|
|
|
|
prime = 0;
|
|
for (i = 0; fmpz_bits(prod) < bit_bound; i++)
|
|
{
|
|
prime = n_nextprime(prime, 0);
|
|
res = fmpz_fdiv_ui(x, prime);
|
|
fmpz_CRT_ui(y, y, prod, res, prime, 1);
|
|
|
|
flint_printf("residue mod %wu = %wu; reconstruction = ", prime, res);
|
|
fmpz_print(y);
|
|
flint_printf("\\n");
|
|
|
|
fmpz_mul_ui(prod, prod, prime);
|
|
}
|
|
|
|
fmpz_clear(x);
|
|
fmpz_clear(y);
|
|
fmpz_clear(prod);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
EOS
|
|
system ENV.cc, "test.c", "-I#{include}/flint", "-L#{lib}", "-L#{Formula["gmp"].lib}",
|
|
"-lflint", "-lgmp", "-o", "test"
|
|
system "./test 2"
|
|
end
|
|
end
|