From 00c6aacf318a6ef0db4895b08d572d924eab90d0 Mon Sep 17 00:00:00 2001 From: James Youngman Date: Thu, 31 Jul 2008 09:58:10 +0200 Subject: factor arbitrarily large numbers * m4/gmp.m4: New file; adds cu_GMP, which detects GNU MP. * configure.ac: Use cu_GMP. * src/Makefile.am: Link factor against libgmp if available. * src/factor.c: Use GNU MP if it is available. (emit_factor, emit_ul_factor, factor_using_division, factor_using_pollard_rho, extract_factors_multi, sort_and_print_factors, free_factors): new functions for the arbitrary-precision implementation, taken from an example in GNU MP. (factor_wheel): Renamed; was called factor. (print_factors_single): Renamed; was called print_factors. (print_factors): New function, chooses between the single- and arbitrary-precision algorithms according to availability of GNU MP and the length of the number to be factored. (usage, main): New options --bignum and --no-bignum. * coreutils.texi (factor invocation): Document new command-line options for the MP implementation and update the performance numbers to take into account the asymptotically faster algorithm. * TODO: Remove item about factoring large primes (it's done). * m4/gmp.m4: Add support for --without-gmp. * NEWS: Mention the new feature. --- m4/gmp.m4 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 m4/gmp.m4 (limited to 'm4') diff --git a/m4/gmp.m4 b/m4/gmp.m4 new file mode 100644 index 000000000..3e6033d47 --- /dev/null +++ b/m4/gmp.m4 @@ -0,0 +1,36 @@ +# Tests for GNU GMP (or any compatible replacement). + +dnl Copyright (C) 2008 Free Software Foundation, Inc. + +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by James Youngman. + +dnl Check for libgmp. We avoid use of AC_CHECK_LIBS because we don't want to +dnl add this to $LIBS for all targets. +AC_DEFUN([cu_GMP], +[ + LIB_GMP= + AC_SUBST([LIB_GMP]) + + AC_ARG_WITH([gmp], + AS_HELP_STRING([--without-gmp], + [do not use the GNU MP library for arbitrary precision + calculation (default: use it if available)]), + [cu_use_gmp=$withval], + [cu_use_gmp=auto]) + + if test $cu_use_gmp != no; then + cu_saved_libs=$LIBS + AC_SEARCH_LIBS([__gmpz_init], [gmp], + [test "$ac_cv_search___gmpz_init" = "none required" || + { + LIB_GMP=$ac_cv_search___gmpz_init + AC_DEFINE([HAVE_GMP], 1, + [Define if you have GNU libgmp (or replacement)]) + }]) + LIBS=$cu_saved_libs + fi +]) -- cgit v1.2.3-70-g09d2