diff options
Diffstat (limited to 'gmp/tests/mpf')
29 files changed, 5032 insertions, 0 deletions
diff --git a/gmp/tests/mpf/Makefile.am b/gmp/tests/mpf/Makefile.am new file mode 100644 index 0000000000..71bccf1a29 --- /dev/null +++ b/gmp/tests/mpf/Makefile.am @@ -0,0 +1,31 @@ +## Process this file with automake to generate Makefile.in + +# Copyright 1996, 1999-2004 Free Software Foundation, Inc. +# +# This file is part of the GNU MP Library test suite. +# +# The GNU MP Library test suite is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the License, +# or (at your option) any later version. +# +# The GNU MP Library test suite is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. + + +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tests +LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la + +check_PROGRAMS = t-add t-sub t-conv t-sqrt t-sqrt_ui t-muldiv t-dm2exp reuse \ + t-cmp_d t-cmp_si t-div t-fits t-get_d t-get_d_2exp \ + t-get_si t-get_ui t-gsprec t-inp_str t-int_p t-mul_ui \ + t-set t-set_q t-set_si t-set_ui t-trunc t-ui_div t-eq +TESTS = $(check_PROGRAMS) + +$(top_builddir)/tests/libtests.la: + cd $(top_builddir)/tests; $(MAKE) $(AM_MAKEFLAGS) libtests.la diff --git a/gmp/tests/mpf/Makefile.in b/gmp/tests/mpf/Makefile.in new file mode 100644 index 0000000000..cbc7bef05b --- /dev/null +++ b/gmp/tests/mpf/Makefile.in @@ -0,0 +1,867 @@ +# Makefile.in generated by automake 1.11.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Copyright 1996, 1999-2004 Free Software Foundation, Inc. +# +# This file is part of the GNU MP Library test suite. +# +# The GNU MP Library test suite is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the License, +# or (at your option) any later version. +# +# The GNU MP Library test suite is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. +VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +check_PROGRAMS = t-add$(EXEEXT) t-sub$(EXEEXT) t-conv$(EXEEXT) \ + t-sqrt$(EXEEXT) t-sqrt_ui$(EXEEXT) t-muldiv$(EXEEXT) \ + t-dm2exp$(EXEEXT) reuse$(EXEEXT) t-cmp_d$(EXEEXT) \ + t-cmp_si$(EXEEXT) t-div$(EXEEXT) t-fits$(EXEEXT) \ + t-get_d$(EXEEXT) t-get_d_2exp$(EXEEXT) t-get_si$(EXEEXT) \ + t-get_ui$(EXEEXT) t-gsprec$(EXEEXT) t-inp_str$(EXEEXT) \ + t-int_p$(EXEEXT) t-mul_ui$(EXEEXT) t-set$(EXEEXT) \ + t-set_q$(EXEEXT) t-set_si$(EXEEXT) t-set_ui$(EXEEXT) \ + t-trunc$(EXEEXT) t-ui_div$(EXEEXT) t-eq$(EXEEXT) +subdir = tests/mpf +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +reuse_SOURCES = reuse.c +reuse_OBJECTS = reuse.$(OBJEXT) +reuse_LDADD = $(LDADD) +reuse_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_add_SOURCES = t-add.c +t_add_OBJECTS = t-add.$(OBJEXT) +t_add_LDADD = $(LDADD) +t_add_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_cmp_d_SOURCES = t-cmp_d.c +t_cmp_d_OBJECTS = t-cmp_d.$(OBJEXT) +t_cmp_d_LDADD = $(LDADD) +t_cmp_d_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_cmp_si_SOURCES = t-cmp_si.c +t_cmp_si_OBJECTS = t-cmp_si.$(OBJEXT) +t_cmp_si_LDADD = $(LDADD) +t_cmp_si_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_conv_SOURCES = t-conv.c +t_conv_OBJECTS = t-conv.$(OBJEXT) +t_conv_LDADD = $(LDADD) +t_conv_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_div_SOURCES = t-div.c +t_div_OBJECTS = t-div.$(OBJEXT) +t_div_LDADD = $(LDADD) +t_div_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_dm2exp_SOURCES = t-dm2exp.c +t_dm2exp_OBJECTS = t-dm2exp.$(OBJEXT) +t_dm2exp_LDADD = $(LDADD) +t_dm2exp_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_eq_SOURCES = t-eq.c +t_eq_OBJECTS = t-eq.$(OBJEXT) +t_eq_LDADD = $(LDADD) +t_eq_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_fits_SOURCES = t-fits.c +t_fits_OBJECTS = t-fits.$(OBJEXT) +t_fits_LDADD = $(LDADD) +t_fits_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_get_d_SOURCES = t-get_d.c +t_get_d_OBJECTS = t-get_d.$(OBJEXT) +t_get_d_LDADD = $(LDADD) +t_get_d_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_get_d_2exp_SOURCES = t-get_d_2exp.c +t_get_d_2exp_OBJECTS = t-get_d_2exp.$(OBJEXT) +t_get_d_2exp_LDADD = $(LDADD) +t_get_d_2exp_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_get_si_SOURCES = t-get_si.c +t_get_si_OBJECTS = t-get_si.$(OBJEXT) +t_get_si_LDADD = $(LDADD) +t_get_si_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_get_ui_SOURCES = t-get_ui.c +t_get_ui_OBJECTS = t-get_ui.$(OBJEXT) +t_get_ui_LDADD = $(LDADD) +t_get_ui_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_gsprec_SOURCES = t-gsprec.c +t_gsprec_OBJECTS = t-gsprec.$(OBJEXT) +t_gsprec_LDADD = $(LDADD) +t_gsprec_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_inp_str_SOURCES = t-inp_str.c +t_inp_str_OBJECTS = t-inp_str.$(OBJEXT) +t_inp_str_LDADD = $(LDADD) +t_inp_str_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_int_p_SOURCES = t-int_p.c +t_int_p_OBJECTS = t-int_p.$(OBJEXT) +t_int_p_LDADD = $(LDADD) +t_int_p_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_mul_ui_SOURCES = t-mul_ui.c +t_mul_ui_OBJECTS = t-mul_ui.$(OBJEXT) +t_mul_ui_LDADD = $(LDADD) +t_mul_ui_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_muldiv_SOURCES = t-muldiv.c +t_muldiv_OBJECTS = t-muldiv.$(OBJEXT) +t_muldiv_LDADD = $(LDADD) +t_muldiv_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_set_SOURCES = t-set.c +t_set_OBJECTS = t-set.$(OBJEXT) +t_set_LDADD = $(LDADD) +t_set_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_set_q_SOURCES = t-set_q.c +t_set_q_OBJECTS = t-set_q.$(OBJEXT) +t_set_q_LDADD = $(LDADD) +t_set_q_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_set_si_SOURCES = t-set_si.c +t_set_si_OBJECTS = t-set_si.$(OBJEXT) +t_set_si_LDADD = $(LDADD) +t_set_si_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_set_ui_SOURCES = t-set_ui.c +t_set_ui_OBJECTS = t-set_ui.$(OBJEXT) +t_set_ui_LDADD = $(LDADD) +t_set_ui_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_sqrt_SOURCES = t-sqrt.c +t_sqrt_OBJECTS = t-sqrt.$(OBJEXT) +t_sqrt_LDADD = $(LDADD) +t_sqrt_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_sqrt_ui_SOURCES = t-sqrt_ui.c +t_sqrt_ui_OBJECTS = t-sqrt_ui.$(OBJEXT) +t_sqrt_ui_LDADD = $(LDADD) +t_sqrt_ui_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_sub_SOURCES = t-sub.c +t_sub_OBJECTS = t-sub.$(OBJEXT) +t_sub_LDADD = $(LDADD) +t_sub_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_trunc_SOURCES = t-trunc.c +t_trunc_OBJECTS = t-trunc.$(OBJEXT) +t_trunc_LDADD = $(LDADD) +t_trunc_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +t_ui_div_SOURCES = t-ui_div.c +t_ui_div_OBJECTS = t-ui_div.$(OBJEXT) +t_ui_div_LDADD = $(LDADD) +t_ui_div_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libgmp.la +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = +am__depfiles_maybe = +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = reuse.c t-add.c t-cmp_d.c t-cmp_si.c t-conv.c t-div.c \ + t-dm2exp.c t-eq.c t-fits.c t-get_d.c t-get_d_2exp.c t-get_si.c \ + t-get_ui.c t-gsprec.c t-inp_str.c t-int_p.c t-mul_ui.c \ + t-muldiv.c t-set.c t-set_q.c t-set_si.c t-set_ui.c t-sqrt.c \ + t-sqrt_ui.c t-sub.c t-trunc.c t-ui_div.c +DIST_SOURCES = reuse.c t-add.c t-cmp_d.c t-cmp_si.c t-conv.c t-div.c \ + t-dm2exp.c t-eq.c t-fits.c t-get_d.c t-get_d_2exp.c t-get_si.c \ + t-get_ui.c t-gsprec.c t-inp_str.c t-int_p.c t-mul_ui.c \ + t-muldiv.c t-set.c t-set_q.c t-set_si.c t-set_ui.c t-sqrt.c \ + t-sqrt_ui.c t-sub.c t-trunc.c t-ui_div.c +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +ETAGS = etags +CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ABI = @ABI@ +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASMFLAGS = @ASMFLAGS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CALLING_CONVENTIONS_OBJS = @CALLING_CONVENTIONS_OBJS@ +CC = @CC@ +CCAS = @CCAS@ +CC_FOR_BUILD = @CC_FOR_BUILD@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CPP_FOR_BUILD = @CPP_FOR_BUILD@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFN_LONG_LONG_LIMB = @DEFN_LONG_LONG_LIMB@ +DEFS = @DEFS@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@ +FGREP = @FGREP@ +GMP_LDFLAGS = @GMP_LDFLAGS@ +GMP_LIMB_BITS = @GMP_LIMB_BITS@ +GMP_NAIL_BITS = @GMP_NAIL_BITS@ +GREP = @GREP@ +HAVE_CLOCK_01 = @HAVE_CLOCK_01@ +HAVE_CPUTIME_01 = @HAVE_CPUTIME_01@ +HAVE_GETRUSAGE_01 = @HAVE_GETRUSAGE_01@ +HAVE_GETTIMEOFDAY_01 = @HAVE_GETTIMEOFDAY_01@ +HAVE_HOST_CPU_FAMILY_power = @HAVE_HOST_CPU_FAMILY_power@ +HAVE_HOST_CPU_FAMILY_powerpc = @HAVE_HOST_CPU_FAMILY_powerpc@ +HAVE_SIGACTION_01 = @HAVE_SIGACTION_01@ +HAVE_SIGALTSTACK_01 = @HAVE_SIGALTSTACK_01@ +HAVE_SIGSTACK_01 = @HAVE_SIGSTACK_01@ +HAVE_STACK_T_01 = @HAVE_STACK_T_01@ +HAVE_SYS_RESOURCE_H_01 = @HAVE_SYS_RESOURCE_H_01@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBCURSES = @LIBCURSES@ +LIBGMPXX_LDFLAGS = @LIBGMPXX_LDFLAGS@ +LIBGMP_DLL = @LIBGMP_DLL@ +LIBGMP_LDFLAGS = @LIBGMP_LDFLAGS@ +LIBM = @LIBM@ +LIBM_FOR_BUILD = @LIBM_FOR_BUILD@ +LIBOBJS = @LIBOBJS@ +LIBREADLINE = @LIBREADLINE@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +M4 = @M4@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SPEED_CYCLECOUNTER_OBJ = @SPEED_CYCLECOUNTER_OBJ@ +STRIP = @STRIP@ +TAL_OBJECT = @TAL_OBJECT@ +TUNE_LIBS = @TUNE_LIBS@ +TUNE_SQR_OBJ = @TUNE_SQR_OBJ@ +U_FOR_BUILD = @U_FOR_BUILD@ +VERSION = @VERSION@ +WITH_READLINE_01 = @WITH_READLINE_01@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__leading_dot = @am__leading_dot@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +gmp_srclinks = @gmp_srclinks@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +mpn_objects = @mpn_objects@ +mpn_objs_in_libgmp = @mpn_objs_in_libgmp@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tests +LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la +TESTS = $(check_PROGRAMS) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu --ignore-deps tests/mpf/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu --ignore-deps tests/mpf/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +reuse$(EXEEXT): $(reuse_OBJECTS) $(reuse_DEPENDENCIES) $(EXTRA_reuse_DEPENDENCIES) + @rm -f reuse$(EXEEXT) + $(LINK) $(reuse_OBJECTS) $(reuse_LDADD) $(LIBS) +t-add$(EXEEXT): $(t_add_OBJECTS) $(t_add_DEPENDENCIES) $(EXTRA_t_add_DEPENDENCIES) + @rm -f t-add$(EXEEXT) + $(LINK) $(t_add_OBJECTS) $(t_add_LDADD) $(LIBS) +t-cmp_d$(EXEEXT): $(t_cmp_d_OBJECTS) $(t_cmp_d_DEPENDENCIES) $(EXTRA_t_cmp_d_DEPENDENCIES) + @rm -f t-cmp_d$(EXEEXT) + $(LINK) $(t_cmp_d_OBJECTS) $(t_cmp_d_LDADD) $(LIBS) +t-cmp_si$(EXEEXT): $(t_cmp_si_OBJECTS) $(t_cmp_si_DEPENDENCIES) $(EXTRA_t_cmp_si_DEPENDENCIES) + @rm -f t-cmp_si$(EXEEXT) + $(LINK) $(t_cmp_si_OBJECTS) $(t_cmp_si_LDADD) $(LIBS) +t-conv$(EXEEXT): $(t_conv_OBJECTS) $(t_conv_DEPENDENCIES) $(EXTRA_t_conv_DEPENDENCIES) + @rm -f t-conv$(EXEEXT) + $(LINK) $(t_conv_OBJECTS) $(t_conv_LDADD) $(LIBS) +t-div$(EXEEXT): $(t_div_OBJECTS) $(t_div_DEPENDENCIES) $(EXTRA_t_div_DEPENDENCIES) + @rm -f t-div$(EXEEXT) + $(LINK) $(t_div_OBJECTS) $(t_div_LDADD) $(LIBS) +t-dm2exp$(EXEEXT): $(t_dm2exp_OBJECTS) $(t_dm2exp_DEPENDENCIES) $(EXTRA_t_dm2exp_DEPENDENCIES) + @rm -f t-dm2exp$(EXEEXT) + $(LINK) $(t_dm2exp_OBJECTS) $(t_dm2exp_LDADD) $(LIBS) +t-eq$(EXEEXT): $(t_eq_OBJECTS) $(t_eq_DEPENDENCIES) $(EXTRA_t_eq_DEPENDENCIES) + @rm -f t-eq$(EXEEXT) + $(LINK) $(t_eq_OBJECTS) $(t_eq_LDADD) $(LIBS) +t-fits$(EXEEXT): $(t_fits_OBJECTS) $(t_fits_DEPENDENCIES) $(EXTRA_t_fits_DEPENDENCIES) + @rm -f t-fits$(EXEEXT) + $(LINK) $(t_fits_OBJECTS) $(t_fits_LDADD) $(LIBS) +t-get_d$(EXEEXT): $(t_get_d_OBJECTS) $(t_get_d_DEPENDENCIES) $(EXTRA_t_get_d_DEPENDENCIES) + @rm -f t-get_d$(EXEEXT) + $(LINK) $(t_get_d_OBJECTS) $(t_get_d_LDADD) $(LIBS) +t-get_d_2exp$(EXEEXT): $(t_get_d_2exp_OBJECTS) $(t_get_d_2exp_DEPENDENCIES) $(EXTRA_t_get_d_2exp_DEPENDENCIES) + @rm -f t-get_d_2exp$(EXEEXT) + $(LINK) $(t_get_d_2exp_OBJECTS) $(t_get_d_2exp_LDADD) $(LIBS) +t-get_si$(EXEEXT): $(t_get_si_OBJECTS) $(t_get_si_DEPENDENCIES) $(EXTRA_t_get_si_DEPENDENCIES) + @rm -f t-get_si$(EXEEXT) + $(LINK) $(t_get_si_OBJECTS) $(t_get_si_LDADD) $(LIBS) +t-get_ui$(EXEEXT): $(t_get_ui_OBJECTS) $(t_get_ui_DEPENDENCIES) $(EXTRA_t_get_ui_DEPENDENCIES) + @rm -f t-get_ui$(EXEEXT) + $(LINK) $(t_get_ui_OBJECTS) $(t_get_ui_LDADD) $(LIBS) +t-gsprec$(EXEEXT): $(t_gsprec_OBJECTS) $(t_gsprec_DEPENDENCIES) $(EXTRA_t_gsprec_DEPENDENCIES) + @rm -f t-gsprec$(EXEEXT) + $(LINK) $(t_gsprec_OBJECTS) $(t_gsprec_LDADD) $(LIBS) +t-inp_str$(EXEEXT): $(t_inp_str_OBJECTS) $(t_inp_str_DEPENDENCIES) $(EXTRA_t_inp_str_DEPENDENCIES) + @rm -f t-inp_str$(EXEEXT) + $(LINK) $(t_inp_str_OBJECTS) $(t_inp_str_LDADD) $(LIBS) +t-int_p$(EXEEXT): $(t_int_p_OBJECTS) $(t_int_p_DEPENDENCIES) $(EXTRA_t_int_p_DEPENDENCIES) + @rm -f t-int_p$(EXEEXT) + $(LINK) $(t_int_p_OBJECTS) $(t_int_p_LDADD) $(LIBS) +t-mul_ui$(EXEEXT): $(t_mul_ui_OBJECTS) $(t_mul_ui_DEPENDENCIES) $(EXTRA_t_mul_ui_DEPENDENCIES) + @rm -f t-mul_ui$(EXEEXT) + $(LINK) $(t_mul_ui_OBJECTS) $(t_mul_ui_LDADD) $(LIBS) +t-muldiv$(EXEEXT): $(t_muldiv_OBJECTS) $(t_muldiv_DEPENDENCIES) $(EXTRA_t_muldiv_DEPENDENCIES) + @rm -f t-muldiv$(EXEEXT) + $(LINK) $(t_muldiv_OBJECTS) $(t_muldiv_LDADD) $(LIBS) +t-set$(EXEEXT): $(t_set_OBJECTS) $(t_set_DEPENDENCIES) $(EXTRA_t_set_DEPENDENCIES) + @rm -f t-set$(EXEEXT) + $(LINK) $(t_set_OBJECTS) $(t_set_LDADD) $(LIBS) +t-set_q$(EXEEXT): $(t_set_q_OBJECTS) $(t_set_q_DEPENDENCIES) $(EXTRA_t_set_q_DEPENDENCIES) + @rm -f t-set_q$(EXEEXT) + $(LINK) $(t_set_q_OBJECTS) $(t_set_q_LDADD) $(LIBS) +t-set_si$(EXEEXT): $(t_set_si_OBJECTS) $(t_set_si_DEPENDENCIES) $(EXTRA_t_set_si_DEPENDENCIES) + @rm -f t-set_si$(EXEEXT) + $(LINK) $(t_set_si_OBJECTS) $(t_set_si_LDADD) $(LIBS) +t-set_ui$(EXEEXT): $(t_set_ui_OBJECTS) $(t_set_ui_DEPENDENCIES) $(EXTRA_t_set_ui_DEPENDENCIES) + @rm -f t-set_ui$(EXEEXT) + $(LINK) $(t_set_ui_OBJECTS) $(t_set_ui_LDADD) $(LIBS) +t-sqrt$(EXEEXT): $(t_sqrt_OBJECTS) $(t_sqrt_DEPENDENCIES) $(EXTRA_t_sqrt_DEPENDENCIES) + @rm -f t-sqrt$(EXEEXT) + $(LINK) $(t_sqrt_OBJECTS) $(t_sqrt_LDADD) $(LIBS) +t-sqrt_ui$(EXEEXT): $(t_sqrt_ui_OBJECTS) $(t_sqrt_ui_DEPENDENCIES) $(EXTRA_t_sqrt_ui_DEPENDENCIES) + @rm -f t-sqrt_ui$(EXEEXT) + $(LINK) $(t_sqrt_ui_OBJECTS) $(t_sqrt_ui_LDADD) $(LIBS) +t-sub$(EXEEXT): $(t_sub_OBJECTS) $(t_sub_DEPENDENCIES) $(EXTRA_t_sub_DEPENDENCIES) + @rm -f t-sub$(EXEEXT) + $(LINK) $(t_sub_OBJECTS) $(t_sub_LDADD) $(LIBS) +t-trunc$(EXEEXT): $(t_trunc_OBJECTS) $(t_trunc_DEPENDENCIES) $(EXTRA_t_trunc_DEPENDENCIES) + @rm -f t-trunc$(EXEEXT) + $(LINK) $(t_trunc_OBJECTS) $(t_trunc_LDADD) $(LIBS) +t-ui_div$(EXEEXT): $(t_ui_div_OBJECTS) $(t_ui_div_DEPENDENCIES) $(EXTRA_t_ui_div_DEPENDENCIES) + @rm -f t-ui_div$(EXEEXT) + $(LINK) $(t_ui_div_OBJECTS) $(t_ui_div_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.c.o: + $(COMPILE) -c $< + +.c.obj: + $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: + $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + fi; \ + echo "$${col}$$dashes$${std}"; \ + echo "$${col}$$banner$${std}"; \ + test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ + test -z "$$report" || echo "$${col}$$report$${std}"; \ + echo "$${col}$$dashes$${std}"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am + + +$(top_builddir)/tests/libtests.la: + cd $(top_builddir)/tests; $(MAKE) $(AM_MAKEFLAGS) libtests.la + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/gmp/tests/mpf/reuse.c b/gmp/tests/mpf/reuse.c new file mode 100644 index 0000000000..3a382530b6 --- /dev/null +++ b/gmp/tests/mpf/reuse.c @@ -0,0 +1,219 @@ +/* Test that routines allow reusing a source variable as destination. + +Copyright 1996, 2000-2002, 2012 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#if __GMP_LIBGMP_DLL + +/* FIXME: When linking to a DLL libgmp, mpf_add etc can't be used as + initializers for global variables because they're effectively global + variables (function pointers) themselves. Perhaps calling a test + function successively with mpf_add etc would be better. */ + +int +main (void) +{ + printf ("Test suppressed for windows DLL\n"); + exit (0); +} + + +#else /* ! DLL_EXPORT */ + +#ifndef SIZE +#define SIZE 16 +#endif + +#ifndef EXPO +#define EXPO 32 +#endif + +void dump_abort (const char *, mpf_t, mpf_t); + +typedef void (*dss_func) (mpf_ptr, mpf_srcptr, mpf_srcptr); + +dss_func dss_funcs[] = +{ + mpf_div, mpf_add, mpf_mul, mpf_sub, +}; + +const char *dss_func_names[] = +{ + "mpf_div", "mpf_add", "mpf_mul", "mpf_sub", +}; + +typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int); + +dsi_func dsi_funcs[] = +{ + mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui, + mpf_mul_2exp, mpf_div_2exp, mpf_pow_ui +}; + +const char *dsi_func_names[] = +{ + "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui", + "mpf_mul_2exp", "mpf_div_2exp", "mpf_pow_ui" +}; + +typedef void (*dis_func) (mpf_ptr, unsigned long int, mpf_srcptr); + +dis_func dis_funcs[] = +{ + mpf_ui_div, mpf_ui_sub, +}; + +const char *dis_func_names[] = +{ + "mpf_ui_div", "mpf_ui_sub", +}; + +int +main (int argc, char **argv) +{ + int i; + int pass, reps = 10000; + mpf_t in1, in2, out1; + unsigned long int in1i, in2i; + mpf_t res1, res2, res3; + mp_size_t bprec = 100; + + tests_start (); + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init (in1); + mpf_init (in2); + mpf_init (out1); + mpf_init (res1); + mpf_init (res2); + mpf_init (res3); + + for (pass = 1; pass <= reps; pass++) + { + mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO); + mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO); + + for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++) + { + /* Don't divide by 0. */ + if (i == 0 && mpf_cmp_ui (in2, 0) == 0) + continue; + + (dss_funcs[i]) (res1, in1, in2); + + mpf_set (out1, in1); + (dss_funcs[i]) (out1, out1, in2); + mpf_set (res2, out1); + + mpf_set (out1, in2); + (dss_funcs[i]) (out1, in1, out1); + mpf_set (res3, out1); + + if (mpf_cmp (res1, res2) != 0) + dump_abort (dss_func_names[i], res1, res2); + if (mpf_cmp (res1, res3) != 0) + dump_abort (dss_func_names[i], res1, res3); + } + + in2i = urandom (); + for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++) + { + unsigned long this_in2i = in2i; + + /* Don't divide by 0. */ + if (dsi_funcs[i] == mpf_div_ui && this_in2i == 0) + continue; + + /* Avoid overflow/underflow in the exponent. */ + if (dsi_funcs[i] == mpf_mul_2exp || dsi_funcs[i] == mpf_div_2exp) + this_in2i %= 0x100000; + else if (dsi_funcs[i] == mpf_pow_ui) + this_in2i %= 0x1000; + + (dsi_funcs[i]) (res1, in1, this_in2i); + + mpf_set (out1, in1); + (dsi_funcs[i]) (out1, out1, this_in2i); + mpf_set (res2, out1); + + if (mpf_cmp (res1, res2) != 0) + dump_abort (dsi_func_names[i], res1, res2); + } + + in1i = urandom (); + for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++) + { + /* Don't divide by 0. */ + if (dis_funcs[i] == mpf_ui_div + && mpf_cmp_ui (in2, 0) == 0) + continue; + + (dis_funcs[i]) (res1, in1i, in2); + + mpf_set (out1, in2); + (dis_funcs[i]) (out1, in1i, out1); + mpf_set (res2, out1); + + if (mpf_cmp (res1, res2) != 0) + dump_abort (dis_func_names[i], res1, res2); + } + + } + + mpf_clear (in1); + mpf_clear (in2); + mpf_clear (out1); + mpf_clear (res1); + mpf_clear (res2); + mpf_clear (res3); + + tests_end (); + exit (0); +} + +void +dump_abort (const char *name, mpf_t res1, mpf_t res2) +{ + printf ("failure in %s:\n", name); + mpf_dump (res1); + mpf_dump (res2); + abort (); +} + +#if 0 +void mpf_abs (mpf_ptr, mpf_srcptr); +void mpf_sqrt (mpf_ptr, mpf_srcptr); +void mpf_neg (mpf_ptr, mpf_srcptr); +#endif + +#endif /* ! DLL_EXPORT */ diff --git a/gmp/tests/mpf/t-add.c b/gmp/tests/mpf/t-add.c new file mode 100644 index 0000000000..dacc6382e4 --- /dev/null +++ b/gmp/tests/mpf/t-add.c @@ -0,0 +1,108 @@ +/* Test mpf_add. + +Copyright 1996, 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 16 +#endif + +int +main (int argc, char **argv) +{ + mp_size_t size; + mp_exp_t exp; + int reps = 20000; + int i; + mpf_t u, v, w, wref; + mp_size_t bprec = 100; + mpf_t rerr, max_rerr, limit_rerr; + + tests_start (); + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, bprec); +#if VERBOSE + mpf_dump (limit_rerr); +#endif + mpf_init (rerr); + mpf_init_set_ui (max_rerr, 0); + + mpf_init (u); + mpf_init (v); + mpf_init (w); + mpf_init (wref); + for (i = 0; i < reps; i++) + { + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (u, size, exp); + + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (v, size, exp); + + mpf_add (w, u, v); + refmpf_add (wref, u, v); + + mpf_reldiff (rerr, w, wref); + if (mpf_cmp (rerr, max_rerr) > 0) + { + mpf_set (max_rerr, rerr); +#if VERBOSE + mpf_dump (max_rerr); +#endif + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf ("wref = "); mpf_dump (wref); + printf (" w = "); mpf_dump (w); + abort (); + } + } + } + + mpf_clear (limit_rerr); + mpf_clear (rerr); + mpf_clear (max_rerr); + + mpf_clear (u); + mpf_clear (v); + mpf_clear (w); + mpf_clear (wref); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-cmp_d.c b/gmp/tests/mpf/t-cmp_d.c new file mode 100644 index 0000000000..a1cbbadb17 --- /dev/null +++ b/gmp/tests/mpf/t-cmp_d.c @@ -0,0 +1,104 @@ +/* Test mpf_cmp_d. + +Copyright 2001, 2003, 2003, 2005 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +#define SGN(n) ((n) > 0 ? 1 : (n) < 0 ? -1 : 0) + +void +check_one (const char *name, mpf_srcptr x, double y, int cmp) +{ + int got; + + got = mpf_cmp_d (x, y); + if (SGN(got) != cmp) + { + int i; + printf ("mpf_cmp_d wrong (from %s)\n", name); + printf (" got %d\n", got); + printf (" want %d\n", cmp); + mpf_trace (" x", x); + printf (" y %g\n", y); + mp_trace_base=-16; + mpf_trace (" x", x); + printf (" y %g\n", y); + printf (" y"); + for (i = 0; i < sizeof(y); i++) + printf (" %02X", (unsigned) ((unsigned char *) &y)[i]); + printf ("\n"); + abort (); + } +} + +void +check_infinity (void) +{ + mpf_t x; + double y = tests_infinity_d (); + if (y == 0.0) + return; + + mpf_init (x); + + /* 0 cmp inf */ + mpf_set_ui (x, 0L); + check_one ("check_infinity", x, y, -1); + check_one ("check_infinity", x, -y, 1); + + /* 123 cmp inf */ + mpf_set_ui (x, 123L); + check_one ("check_infinity", x, y, -1); + check_one ("check_infinity", x, -y, 1); + + /* -123 cmp inf */ + mpf_set_si (x, -123L); + check_one ("check_infinity", x, y, -1); + check_one ("check_infinity", x, -y, 1); + + /* 2^5000 cmp inf */ + mpf_set_ui (x, 1L); + mpf_mul_2exp (x, x, 5000L); + check_one ("check_infinity", x, y, -1); + check_one ("check_infinity", x, -y, 1); + + /* -2^5000 cmp inf */ + mpf_neg (x, x); + check_one ("check_infinity", x, y, -1); + check_one ("check_infinity", x, -y, 1); + + mpf_clear (x); +} + +int +main (int argc, char *argv[]) +{ + tests_start (); + + check_infinity (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-cmp_si.c b/gmp/tests/mpf/t-cmp_si.c new file mode 100644 index 0000000000..3bf016ff28 --- /dev/null +++ b/gmp/tests/mpf/t-cmp_si.c @@ -0,0 +1,107 @@ +/* Test mpf_cmp_si. + +Copyright 2000, 2001, 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#define SGN(x) ((x) < 0 ? -1 : (x) == 0 ? 0 : 1) + +void +check_data (void) +{ + static const struct { + int a_base; + const char *a; + const char *b; + int want; + } data[] = { + { 10, "0", "1", -1 }, + { 10, "0", "0", 0 }, + { 10, "0", "-1", 1 }, + + { 10, "1", "1", 0 }, + { 10, "1", "0", 1 }, + { 10, "1", "-1", 1 }, + + { 10, "-1", "1", -1 }, + { 10, "-1", "0", -1 }, + { 10, "-1", "-1", 0 }, + + { 16, "0", "-0x80000000", 1 }, + { 16, "80000000", "-0x80000000", 1 }, + { 16, "80000001", "-0x80000000", 1 }, + { 16, "-80000000", "-0x80000000", 0 }, + { 16, "-80000001", "-0x80000000", -1 }, + { 16, "-FF0080000001", "-0x80000000", -1 }, + + { 16, "0", "-0x8000000000000000", 1 }, + { 16, "8000000000000000", "-0x8000000000000000", 1 }, + { 16, "8000000000000001", "-0x8000000000000000", 1 }, + { 16, "-8000000000000000", "-0x8000000000000000", 0 }, + { 16, "-8000000000000001", "-0x8000000000000000", -1 }, + { 16, "-FF008000000000000001", "-0x8000000000000000", -1 }, + }; + + mpf_t a; + mpz_t bz; + long b; + int got; + int i; + + mpf_init (a); + mpz_init (bz); + for (i = 0; i < numberof (data); i++) + { + mpf_set_str_or_abort (a, data[i].a, data[i].a_base); + mpz_set_str_or_abort (bz, data[i].b, 0); + + if (mpz_fits_slong_p (bz)) + { + b = mpz_get_si (bz); + got = mpf_cmp_si (a, b); + if (SGN (got) != data[i].want) + { + printf ("mpf_cmp_si wrong on data[%d]\n", i); + printf (" a="); mpf_out_str (stdout, 10, 0, a); + printf (" (%s)\n", data[i].a); + printf (" b=%ld (%s)\n", b, data[i].b); + printf (" got=%d\n", got); + printf (" want=%d\n", data[i].want); + abort(); + } + } + } + + mpf_clear (a); + mpz_clear (bz); +} + +int +main (void) +{ + tests_start (); + + check_data (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-conv.c b/gmp/tests/mpf/t-conv.c new file mode 100644 index 0000000000..3b47866061 --- /dev/null +++ b/gmp/tests/mpf/t-conv.c @@ -0,0 +1,143 @@ +/* Test mpf_get_str and mpf_set_str. + +Copyright 1996, 2000, 2001, 2008 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> /* for strlen */ + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 10 +#endif + +#ifndef EXPO +#define EXPO 200 +#endif + +int +main (int argc, char **argv) +{ + mpf_t x, y; + int reps = 20000; + int i; + mp_size_t bprec = 100; + mpf_t d, rerr, max_rerr, limit_rerr; + char *str; + mp_exp_t bexp; + long size, exp; + int base; + char buf[SIZE * GMP_LIMB_BITS + 5]; + + tests_start (); + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, bprec); +#if VERBOSE + mpf_dump (limit_rerr); +#endif + mpf_init (rerr); + mpf_init_set_ui (max_rerr, 0); + + mpf_init (x); + mpf_init (y); + mpf_init (d); + + /* First test some specific values. */ + + mpf_set_str (y, "1.23456e1000", 0); + + mpf_set_str (x, "1.23456e1000", 10); + if (mpf_cmp (x, y) != 0) + abort (); + mpf_set_str (x, "1.23456e+1000", 0); + if (mpf_cmp (x, y) != 0) + abort (); + mpf_set_str (x, "1.23456e+1000", 10); + if (mpf_cmp (x, y) != 0) + abort (); + + /* Now test random values. */ + + for (i = 0; i < reps; i++) + { + if (i == 0) + { + /* exercise the special case in get_str for for x==0 */ + mpf_set_ui (x, 0L); + base = 10; + } + else + { + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % EXPO; + mpf_random2 (x, size, exp); + base = urandom () % 61 + 2; + } + + str = mpf_get_str (0, &bexp, base, 0, x); + + if (str[0] == '-') + sprintf (buf, "-0.%s@%ld", str + 1, bexp); + else + sprintf (buf, "0.%s@%ld", str, bexp); + + mpf_set_str_or_abort (y, buf, -base); + (*__gmp_free_func) (str, strlen (str) + 1); + + mpf_reldiff (rerr, x, y); + if (mpf_cmp (rerr, max_rerr) > 0) + { + mpf_set (max_rerr, rerr); +#if VERBOSE + mpf_dump (max_rerr); +#endif + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR after %d tests\n", i); + printf ("base = %d\n", base); + printf (" x = "); mpf_dump (x); + printf (" y = "); mpf_dump (y); + abort (); + } + } + } + + mpf_clear (limit_rerr); + mpf_clear (rerr); + mpf_clear (max_rerr); + + mpf_clear (x); + mpf_clear (y); + mpf_clear (d); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-div.c b/gmp/tests/mpf/t-div.c new file mode 100644 index 0000000000..2f34eabaca --- /dev/null +++ b/gmp/tests/mpf/t-div.c @@ -0,0 +1,186 @@ +/* Test mpf_div. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_one (const char *desc, mpf_ptr got, mpf_srcptr u, mpf_srcptr v) +{ + if (! refmpf_validate_division ("mpf_div", got, u, v)) + { + mp_trace_base = -16; + mpf_trace (" u", u); + mpf_trace (" v", v); + printf (" %s\n", desc); + abort (); + } +} + +void +check_rand (void) +{ + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long prec; + mpf_t got, u, v; + int i; + + mpf_init (got); + mpf_init (u); + mpf_init (v); + + /* separate */ + for (i = 0; i < 100; i++) + { + /* got precision */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (got, prec); + + /* u */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (u, prec); + do { + mpf_random2 (u, PREC(u), (mp_exp_t) 20); + } while (SIZ(u) == 0); + if (gmp_urandomb_ui (rands, 1L)) + mpf_neg (u, u); + + /* v */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (v, prec); + do { + mpf_random2 (v, PREC(v), (mp_exp_t) 20); + } while (SIZ(v) == 0); + if (gmp_urandomb_ui (rands, 1L)) + mpf_neg (v, v); + + switch (i % 3) { + case 0: + mpf_div (got, u, v); + check_one ("separate", got, u, v); + break; + case 1: + prec = refmpf_set_overlap (got, u); + mpf_div (got, got, v); + check_one ("dst == u", got, u, v); + mpf_set_prec_raw (got, prec); + break; + case 2: + prec = refmpf_set_overlap (got, v); + mpf_div (got, u, got); + check_one ("dst == v", got, u, v); + mpf_set_prec_raw (got, prec); + break; + } + } + + mpf_clear (got); + mpf_clear (u); + mpf_clear (v); +} + +/* Exercise calls mpf(x,x,x) */ +void +check_reuse_three (void) +{ + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long result_prec, input_prec, set_prec; + mpf_t got; + int i; + + mpf_init (got); + + for (i = 0; i < 8; i++) + { + result_prec = min_prec + gmp_urandomm_ui (rands, 15L); + input_prec = min_prec + gmp_urandomm_ui (rands, 15L); + + set_prec = MAX (result_prec, input_prec); + refmpf_set_prec_limbs (got, set_prec); + + /* input, non-zero, possibly negative */ + PREC(got) = input_prec; + do { + mpf_random2 (got, input_prec, (mp_exp_t) 20); + } while (SIZ(got) == 0); + if (gmp_urandomb_ui (rands, 1L)) + mpf_neg (got, got); + + PREC(got) = result_prec; + + mpf_div (got, got, got); + + /* expect exactly 1.0 always */ + ASSERT_ALWAYS (mpf_cmp_ui (got, 1L) == 0); + + PREC(got) = set_prec; + } + + mpf_clear (got); +} + +void +check_various (void) +{ + mpf_t got, u, v; + + mpf_init (got); + mpf_init (u); + mpf_init (v); + + /* 100/4 == 25 */ + mpf_set_prec (got, 20L); + mpf_set_ui (u, 100L); + mpf_set_ui (v, 4L); + mpf_div (got, u, v); + MPF_CHECK_FORMAT (got); + ASSERT_ALWAYS (mpf_cmp_ui (got, 25L) == 0); + + /* 1/(2^n+1), a case where truncating the divisor would be wrong */ + mpf_set_prec (got, 500L); + mpf_set_prec (v, 900L); + mpf_set_ui (v, 1L); + mpf_mul_2exp (v, v, 800L); + mpf_add_ui (v, v, 1L); + mpf_div (got, u, v); + check_one ("1/2^n+1, separate", got, u, v); + + mpf_clear (got); + mpf_clear (u); + mpf_clear (v); +} + +int +main (void) +{ + tests_start (); + + check_various (); + check_rand (); + check_reuse_three (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-dm2exp.c b/gmp/tests/mpf/t-dm2exp.c new file mode 100644 index 0000000000..90e4c18f16 --- /dev/null +++ b/gmp/tests/mpf/t-dm2exp.c @@ -0,0 +1,119 @@ +/* Test mpf_div, mpf_div_2exp, mpf_mul_2exp. + +Copyright 1996, 2000, 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 16 +#endif + +int +main (int argc, char **argv) +{ + int reps = 100000; + int i; + mpf_t u, v, w1, w2, w3; + mp_size_t bprec = 100; + mpf_t rerr, limit_rerr; + mp_size_t un; + mp_exp_t ue; + + tests_start (); + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init (rerr); + mpf_init (limit_rerr); + + mpf_init (u); + mpf_init (v); + mpf_init (w1); + mpf_init (w2); + mpf_init (w3); + + for (i = 0; i < reps; i++) + { + unsigned long int res_prec; + unsigned long int pow2; + + res_prec = urandom () % (bprec + 100); + mpf_set_prec (w1, res_prec); + mpf_set_prec (w2, res_prec); + mpf_set_prec (w3, res_prec); + + mpf_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, res_prec); + + pow2 = urandom () % 0x10000; + mpf_set_ui (v, 1); + mpf_mul_2exp (v, v, pow2); + + un = urandom () % (2 * SIZE) - SIZE; + ue = urandom () % SIZE; + mpf_random2 (u, un, ue); + + mpf_div_2exp (w1, u, pow2); + mpf_div (w2, u, v); + mpf_reldiff (rerr, w1, w2); + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf (" w1 = "); mpf_dump (w1); + printf (" w2 = "); mpf_dump (w2); + abort (); + } + mpf_mul_2exp (w3, w1, pow2); + mpf_reldiff (rerr, u, w3); + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR in mpf_mul_2exp after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf (" w1 = "); mpf_dump (w1); + printf (" w3 = "); mpf_dump (w3); + abort (); + } + } + + mpf_clear (rerr); + mpf_clear (limit_rerr); + + mpf_clear (u); + mpf_clear (v); + mpf_clear (w1); + mpf_clear (w2); + mpf_clear (w3); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-eq.c b/gmp/tests/mpf/t-eq.c new file mode 100644 index 0000000000..359fec9316 --- /dev/null +++ b/gmp/tests/mpf/t-eq.c @@ -0,0 +1,218 @@ +/* Test mpf_eq. + +Copyright 2009, 2012 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#define SZ (2 * sizeof(mp_limb_t)) + +void insert_random_low_zero_limbs (mpf_t, gmp_randstate_ptr); +void dump_abort (mpf_t, mpf_t, int, int, int, int, int, long); +void hexdump (mpf_t); + +void +check_data (void) +{ + static const struct + { + struct { + int exp, size; + mp_limb_t d[10]; + } x, y; + mp_bitcnt_t bits; + int want; + + } data[] = { + { { 0, 0, { 0 } }, { 0, 0, { 0 } }, 0, 1 }, + + { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 0, 1 }, + { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 17, 1 }, + { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 4711, 1 }, + + { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 0, 1 }, + { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 2, 1 }, + { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 3, 0 }, + + { { 0, 0, { 0 } }, { 0, 1, { 1 } }, 0, 0 }, + { { 0, 1, { 1 } }, { 0,-1 ,{ 1 } }, 0, 0 }, + { { 1, 1, { 1 } }, { 0, 1, { 1 } }, 0, 0 }, + + { { 0, 1, { 8 } }, { 0, 1, { 4 } }, 0, 0 }, + + { { 0, 2, { 0, 3 } }, { 0, 1, { 3 } }, 1000, 1 }, + }; + + mpf_t x, y; + int got, got_swapped; + int i; + mp_trace_base = 16; + + for (i = 0; i < numberof (data); i++) + { + PTR(x) = (mp_ptr) data[i].x.d; + SIZ(x) = data[i].x.size; + EXP(x) = data[i].x.exp; + PREC(x) = numberof (data[i].x.d); + MPF_CHECK_FORMAT (x); + + PTR(y) = (mp_ptr) data[i].y.d; + SIZ(y) = data[i].y.size; + EXP(y) = data[i].y.exp; + PREC(y) = numberof (data[i].y.d); + MPF_CHECK_FORMAT (y); + + got = mpf_eq (x, y, data[i].bits); + got_swapped = mpf_eq (y, x, data[i].bits); + + if (got != got_swapped || got != data[i].want) + { + printf ("check_data() wrong result at data[%d]\n", i); + mpf_trace ("x ", x); + mpf_trace ("y ", y); + printf ("got %d\n", got); + printf ("got_swapped %d\n", got_swapped); + printf ("want %d\n", data[i].want); + abort (); + } + } +} + +void +check_random (long reps) +{ + unsigned long test; + gmp_randstate_ptr rands = RANDS; + mpf_t a, b, x; + mpz_t ds; + int hibits, lshift1, lshift2; + int xtra; + +#define HIBITS 10 +#define LSHIFT1 10 +#define LSHIFT2 10 + + mpf_set_default_prec ((1 << HIBITS) + (1 << LSHIFT1) + (1 << LSHIFT2)); + + mpz_init (ds); + mpf_inits (a, b, x, NULL); + + for (test = 0; test < reps; test++) + { + mpz_urandomb (ds, rands, HIBITS); + hibits = mpz_get_ui (ds) + 1; + mpz_urandomb (ds, rands, hibits); + mpz_setbit (ds, hibits - 1); /* make sure msb is set */ + mpf_set_z (a, ds); + mpf_set_z (b, ds); + + mpz_urandomb (ds, rands, LSHIFT1); + lshift1 = mpz_get_ui (ds); + mpf_mul_2exp (a, a, lshift1 + 1); + mpf_mul_2exp (b, b, lshift1 + 1); + mpf_add_ui (a, a, 1); /* make a one-bit difference */ + + mpz_urandomb (ds, rands, LSHIFT2); + lshift2 = mpz_get_ui (ds); + mpf_mul_2exp (a, a, lshift2); + mpf_mul_2exp (b, b, lshift2); + mpz_urandomb (ds, rands, lshift2); + mpf_set_z (x, ds); + mpf_add (a, a, x); + mpf_add (b, b, x); + + insert_random_low_zero_limbs (a, rands); + insert_random_low_zero_limbs (b, rands); + + if (mpf_eq (a, b, lshift1 + hibits) == 0 || + mpf_eq (b, a, lshift1 + hibits) == 0) + { + dump_abort (a, b, lshift1 + hibits, lshift1, lshift2, hibits, 1, test); + } + for (xtra = 1; xtra < 100; xtra++) + if (mpf_eq (a, b, lshift1 + hibits + xtra) != 0 || + mpf_eq (b, a, lshift1 + hibits + xtra) != 0) + { + dump_abort (a, b, lshift1 + hibits + xtra, lshift1, lshift2, hibits, 0, test); + } + } + + mpf_clears (a, b, x, NULL); + mpz_clear (ds); +} + +void +insert_random_low_zero_limbs (mpf_t x, gmp_randstate_ptr rands) +{ + mp_size_t max = PREC(x) - SIZ(x); + mp_size_t s; + mpz_t ds; mpz_init (ds); + mpz_urandomb (ds, rands, 32); + s = mpz_get_ui (ds) % (max + 1); + MPN_COPY_DECR (PTR(x) + s, PTR(x), SIZ(x)); + MPN_ZERO (PTR(x), s); + SIZ(x) += s; + mpz_clear (ds); +} + +void +dump_abort (mpf_t a, mpf_t b, int cmp_prec, int lshift1, int lshift2, int hibits, int want, long test) +{ + printf ("ERROR in test %ld\n", test); + printf ("want %d got %d from mpf_eq\n", want, 1-want); + printf ("cmp_prec = %d\n", cmp_prec); + printf ("lshift1 = %d\n", lshift1); + printf ("lshift2 = %d\n", lshift2); + printf ("hibits = %d\n", hibits); + hexdump (a); puts (""); + hexdump (b); puts (""); + abort (); +} + +void +hexdump (mpf_t x) +{ + mp_size_t i; + for (i = ABSIZ(x) - 1; i >= 0; i--) + { + gmp_printf ("%0*MX", SZ, PTR(x)[i]); + if (i != 0) + printf (" "); + } +} + +int +main (int argc, char *argv[]) +{ + long reps = 10000; + + if (argc == 2) + reps = strtol (argv[1], 0, 0); + + tests_start (); + + check_data (); + check_random (reps); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-fits.c b/gmp/tests/mpf/t-fits.c new file mode 100644 index 0000000000..4b0e7c56ba --- /dev/null +++ b/gmp/tests/mpf/t-fits.c @@ -0,0 +1,333 @@ +/* Test mpf_fits_*_p + +Copyright 2001, 2002, 2013 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +/* Nothing sophisticated here, just exercise mpf_fits_*_p on a small amount + of data. */ + +#define EXPECT_S(fun,name,answer) \ + got = fun (f); \ + if (got != answer) \ + { \ + printf ("%s (%s) got %d want %d\n", name, expr, got, answer); \ + printf (" f size %d exp %ld\n", SIZ(f), EXP(f)); \ + printf (" f dec "); mpf_out_str (stdout, 10, 0, f); printf ("\n"); \ + printf (" f hex "); mpf_out_str (stdout, 16, 0, f); printf ("\n"); \ + error = 1; \ + } + +#if HAVE_STRINGIZE +#define EXPECT(fun,answer) EXPECT_S(fun,#fun,answer) +#else +#define EXPECT(fun,answer) EXPECT_S(fun,"fun",answer) +#endif + +int +main (void) +{ + mpf_t f, f0p5; + int got; + const char *expr; + int error = 0; + + tests_start (); + mpf_init2 (f, 200L); + mpf_init2 (f0p5, 200L); + + /* 0.5 */ + mpf_set_ui (f0p5, 1L); + mpf_div_2exp (f0p5, f0p5, 1L); + + mpf_set_ui (f, 0L); + expr = "0"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_ui (f, 1L); + expr = "1"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_si (f, -1L); + expr = "-1"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + + mpf_set_ui (f, (unsigned long) USHRT_MAX); + expr = "USHRT_MAX"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + + mpf_set_ui (f, (unsigned long) USHRT_MAX); + mpf_add (f, f, f0p5); + expr = "USHRT_MAX + 0.5"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + + mpf_set_ui (f, (unsigned long) USHRT_MAX); + mpf_add_ui (f, f, 1L); + expr = "USHRT_MAX + 1"; + EXPECT (mpf_fits_ushort_p, 0); + + + mpf_set_ui (f, (unsigned long) UINT_MAX); + expr = "UINT_MAX"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + + mpf_set_ui (f, (unsigned long) UINT_MAX); + mpf_add (f, f, f0p5); + expr = "UINT_MAX + 0.5"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + + mpf_set_ui (f, (unsigned long) UINT_MAX); + mpf_add_ui (f, f, 1L); + expr = "UINT_MAX + 1"; + EXPECT (mpf_fits_uint_p, 0); + + + mpf_set_ui (f, ULONG_MAX); + expr = "ULONG_MAX"; + EXPECT (mpf_fits_ulong_p, 1); + + mpf_set_ui (f, ULONG_MAX); + mpf_add (f, f, f0p5); + expr = "ULONG_MAX + 0.5"; + EXPECT (mpf_fits_ulong_p, 1); + + mpf_set_ui (f, ULONG_MAX); + mpf_add_ui (f, f, 1L); + expr = "ULONG_MAX + 1"; + EXPECT (mpf_fits_ulong_p, 0); + + + mpf_set_si (f, (long) SHRT_MAX); + expr = "SHRT_MAX"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_si (f, (long) SHRT_MAX); + expr = "SHRT_MAX + 0.5"; + mpf_add (f, f, f0p5); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_si (f, (long) SHRT_MAX); + mpf_add_ui (f, f, 1L); + expr = "SHRT_MAX + 1"; + EXPECT (mpf_fits_sshort_p, 0); + + + mpf_set_si (f, (long) INT_MAX); + expr = "INT_MAX"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + + mpf_set_si (f, (long) INT_MAX); + mpf_add (f, f, f0p5); + expr = "INT_MAX + 0.5"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + + mpf_set_si (f, (long) INT_MAX); + mpf_add_ui (f, f, 1L); + expr = "INT_MAX + 1"; + EXPECT (mpf_fits_sint_p, 0); + + + mpf_set_si (f, LONG_MAX); + expr = "LONG_MAX"; + EXPECT (mpf_fits_slong_p, 1); + + mpf_set_si (f, LONG_MAX); + mpf_add (f, f, f0p5); + expr = "LONG_MAX + 0.5"; + EXPECT (mpf_fits_slong_p, 1); + + mpf_set_si (f, LONG_MAX); + mpf_add_ui (f, f, 1L); + expr = "LONG_MAX + 1"; + EXPECT (mpf_fits_slong_p, 0); + + + mpf_set_si (f, (long) SHRT_MIN); + expr = "SHRT_MIN"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_si (f, (long) SHRT_MIN); + mpf_sub (f, f, f0p5); + expr = "SHRT_MIN - 0.5"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_si (f, (long) SHRT_MIN); + mpf_sub_ui (f, f, 1L); + expr = "SHRT_MIN - 1"; + EXPECT (mpf_fits_sshort_p, 0); + + + mpf_set_si (f, (long) INT_MIN); + expr = "INT_MIN"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + + mpf_set_si (f, (long) INT_MIN); + mpf_sub (f, f, f0p5); + expr = "INT_MIN - 0.5"; + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + + mpf_set_si (f, (long) INT_MIN); + mpf_sub_ui (f, f, 1L); + expr = "INT_MIN - 1"; + EXPECT (mpf_fits_sint_p, 0); + + + mpf_set_si (f, LONG_MIN); + expr = "LONG_MIN"; + EXPECT (mpf_fits_slong_p, 1); + + mpf_set_si (f, LONG_MIN); + mpf_sub (f, f, f0p5); + expr = "LONG_MIN - 0.5"; + EXPECT (mpf_fits_slong_p, 1); + + mpf_set_si (f, LONG_MIN); + mpf_sub_ui (f, f, 1L); + expr = "LONG_MIN - 1"; + EXPECT (mpf_fits_slong_p, 0); + + + mpf_set_str_or_abort (f, "0.5", 10); + expr = "0.5"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_str_or_abort (f, "-0.5", 10); + expr = "-0.5"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_str_or_abort (f, "-1.5", 10); + expr = "-1.5"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + + mpf_set_str_or_abort (f, "1.000000000000000000000000000000000001", 16); + expr = "1.000000000000000000000000000000000001 base 16"; + EXPECT (mpf_fits_ulong_p, 1); + EXPECT (mpf_fits_uint_p, 1); + EXPECT (mpf_fits_ushort_p, 1); + EXPECT (mpf_fits_slong_p, 1); + EXPECT (mpf_fits_sint_p, 1); + EXPECT (mpf_fits_sshort_p, 1); + + mpf_set_str_or_abort (f, "1@1000", 16); + expr = "1@1000 base 16"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 0); + EXPECT (mpf_fits_sint_p, 0); + EXPECT (mpf_fits_sshort_p, 0); + + + mpf_set_ui (f, 1L); + mpf_mul_2exp (f, f, BITS_PER_ULONG + 1); + mpf_sub_ui (f, f, 1L); + expr = "2^(BITS_PER_ULONG+1) - 1"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 0); + EXPECT (mpf_fits_sint_p, 0); + EXPECT (mpf_fits_sshort_p, 0); + + mpf_set_ui (f, 1L); + mpf_mul_2exp (f, f, BITS_PER_ULONG + 1); + mpf_sub_ui (f, f, 1L); + mpf_neg (f, f); + expr = "- (2^(BITS_PER_ULONG+1) - 1)"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 0); + EXPECT (mpf_fits_sint_p, 0); + EXPECT (mpf_fits_sshort_p, 0); + + mpf_set_ui (f, 1L); + mpf_mul_2exp (f, f, BITS_PER_ULONG + 5); + mpf_sub_ui (f, f, 1L); + expr = "2^(BITS_PER_ULONG+5) - 1"; + EXPECT (mpf_fits_ulong_p, 0); + EXPECT (mpf_fits_uint_p, 0); + EXPECT (mpf_fits_ushort_p, 0); + EXPECT (mpf_fits_slong_p, 0); + EXPECT (mpf_fits_sint_p, 0); + EXPECT (mpf_fits_sshort_p, 0); + + + if (error) + abort (); + + mpf_clear (f); + mpf_clear (f0p5); + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-get_d.c b/gmp/tests/mpf/t-get_d.c new file mode 100644 index 0000000000..66b9623f90 --- /dev/null +++ b/gmp/tests/mpf/t-get_d.c @@ -0,0 +1,106 @@ +/* Test mpf_get_d and mpf_set_d. + +Copyright 1996, 1999-2001, 2009 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "tests.h" + +#if defined (__vax) || defined (__vax__) +#define LOW_BOUND 1e-38 +#define HIGH_BOUND 8e37 +#endif + +#if defined (_CRAY) && ! defined (_CRAYIEEE) +/* The range varies mysteriously between Cray version. On an SV1, + the range seem to be 1e-600..1e603, but a cfp (non-ieee) T90 + has a much smaller range of 1e-240..1e240. */ +#define LOW_BOUND 1e-240 +#define HIGH_BOUND 1e240 +#endif + +#if ! defined (LOW_BOUND) +#define LOW_BOUND 1e-300 +#define HIGH_BOUND 1e300 +#endif + +void +test_denorms (int prc) +{ +#ifdef _GMP_IEEE_FLOATS + double d1, d2; + mpf_t f; + int i; + + mpf_set_default_prec (prc); + + mpf_init (f); + + d1 = 1.9; + for (i = 0; i < 820; i++) + { + mpf_set_d (f, d1); + d2 = mpf_get_d (f); + if (d1 != d2) + abort (); + d1 *= 0.4; + } + + mpf_clear (f); +#endif +} + +int +main (int argc, char **argv) +{ + double d, e, r; + mpf_t u, v; + + tests_start (); + mpf_init (u); + mpf_init (v); + + mpf_set_d (u, LOW_BOUND); + for (d = 2.0 * LOW_BOUND; d < HIGH_BOUND; d *= 1.01) + { + mpf_set_d (v, d); + if (mpf_cmp (u, v) >= 0) + abort (); + e = mpf_get_d (v); + r = e/d; + if (r < 0.99999999999999 || r > 1.00000000000001) + { + fprintf (stderr, "should be one ulp from 1: %.16f\n", r); + abort (); + } + mpf_set (u, v); + } + + mpf_clear (u); + mpf_clear (v); + + test_denorms (10); + test_denorms (32); + test_denorms (64); + test_denorms (100); + test_denorms (200); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-get_d_2exp.c b/gmp/tests/mpf/t-get_d_2exp.c new file mode 100644 index 0000000000..891e51d5a5 --- /dev/null +++ b/gmp/tests/mpf/t-get_d_2exp.c @@ -0,0 +1,121 @@ +/* Test mpf_get_d_2exp. + +Copyright 2002, 2003 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +static void +check_onebit (void) +{ + static const long data[] = { + -513, -512, -511, -65, -64, -63, -32, -1, + 0, 1, 32, 53, 54, 64, 128, 256, 511, 512, 513 + }; + mpf_t f; + double got, want; + long got_exp, want_exp; + int i; + + mpf_init2 (f, 1024L); + + for (i = 0; i < numberof (data); i++) + { + mpf_set_ui (f, 1L); + if (data[i] >= 0) + mpf_mul_2exp (f, f, data[i]); + else + mpf_div_2exp (f, f, -data[i]); + want = 0.5; + want_exp = data[i] + 1; + + got = mpf_get_d_2exp (&got_exp, f); + if (got != want || got_exp != want_exp) + { + printf ("mpf_get_d_2exp wrong on 2**%ld\n", data[i]); + mpf_trace (" f ", f); + d_trace (" want ", want); + d_trace (" got ", got); + printf (" want exp %ld\n", want_exp); + printf (" got exp %ld\n", got_exp); + abort(); + } + } + mpf_clear (f); +} + +/* Check that hardware rounding doesn't make mpf_get_d_2exp return a value + outside its defined range. */ +static void +check_round (void) +{ + static const unsigned long data[] = { 1, 32, 53, 54, 64, 128, 256, 512 }; + mpf_t f; + double got; + long got_exp; + int i, rnd_mode, old_rnd_mode; + + mpf_init2 (f, 1024L); + old_rnd_mode = tests_hardware_getround (); + + for (rnd_mode = 0; rnd_mode < 4; rnd_mode++) + { + tests_hardware_setround (rnd_mode); + + for (i = 0; i < numberof (data); i++) + { + mpf_set_ui (f, 1L); + mpf_mul_2exp (f, f, data[i]); + mpf_sub_ui (f, f, 1L); + + got = mpf_get_d_2exp (&got_exp, f); + if (got < 0.5 || got >= 1.0) + { + printf ("mpf_get_d_2exp bad on 2**%lu-1\n", data[i]); + printf ("result out of range, expect 0.5 <= got < 1.0\n"); + printf (" rnd_mode = %d\n", rnd_mode); + printf (" data[i] = %lu\n", data[i]); + mpf_trace (" f ", f); + d_trace (" got ", got); + printf (" got exp %ld\n", got_exp); + abort(); + } + } + } + + mpf_clear (f); + tests_hardware_setround (old_rnd_mode); +} + + +int +main (void) +{ + tests_start (); + mp_trace_base = 16; + + check_onebit (); + check_round (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-get_si.c b/gmp/tests/mpf/t-get_si.c new file mode 100644 index 0000000000..80362616d7 --- /dev/null +++ b/gmp/tests/mpf/t-get_si.c @@ -0,0 +1,223 @@ +/* Exercise mpz_get_si. + +Copyright 2000, 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_data (void) +{ + static const struct { + int base; + const char *f; + long want; + } data[] = { + { 10, "0", 0L }, + { 10, "1", 1L }, + { 10, "-1", -1L }, + { 10, "2", 2L }, + { 10, "-2", -2L }, + { 10, "12345", 12345L }, + { 10, "-12345", -12345L }, + + /* fraction bits ignored */ + { 10, "0.5", 0L }, + { 10, "-0.5", 0L }, + { 10, "1.1", 1L }, + { 10, "-1.1", -1L }, + { 10, "1.9", 1L }, + { 10, "-1.9", -1L }, + { 16, "1.000000000000000000000000000000000000000000000000001", 1L }, + { 16, "-1.000000000000000000000000000000000000000000000000001", -1L }, + + /* low bits extracted (this is undocumented) */ + { 16, "1000000000000000000000000000000000000000000000000001", 1L }, + { 16, "-1000000000000000000000000000000000000000000000000001", -1L }, + }; + + int i; + mpf_t f; + long got; + + mpf_init2 (f, 2000L); + for (i = 0; i < numberof (data); i++) + { + mpf_set_str_or_abort (f, data[i].f, data[i].base); + + got = mpf_get_si (f); + if (got != data[i].want) + { + printf ("mpf_get_si wrong at data[%d]\n", i); + printf (" f \"%s\"\n", data[i].f); + printf (" dec "); mpf_out_str (stdout, 10, 0, f); printf ("\n"); + printf (" hex "); mpf_out_str (stdout, 16, 0, f); printf ("\n"); + printf (" size %ld\n", (long) SIZ(f)); + printf (" exp %ld\n", (long) EXP(f)); + printf (" got %ld (0x%lX)\n", got, got); + printf (" want %ld (0x%lX)\n", data[i].want, data[i].want); + abort(); + } + } + mpf_clear (f); +} + + +void +check_max (void) +{ + mpf_t f; + long want; + long got; + + mpf_init2 (f, 200L); + +#define CHECK_MAX(name) \ + if (got != want) \ + { \ + printf ("mpf_get_si wrong on %s\n", name); \ + printf (" f "); \ + mpf_out_str (stdout, 10, 0, f); printf (", hex "); \ + mpf_out_str (stdout, 16, 0, f); printf ("\n"); \ + printf (" got %ld, hex %lX\n", got, got); \ + printf (" want %ld, hex %lX\n", want, want); \ + abort(); \ + } + + want = LONG_MAX; + mpf_set_si (f, want); + got = mpf_get_si (f); + CHECK_MAX ("LONG_MAX"); + + want = LONG_MIN; + mpf_set_si (f, want); + got = mpf_get_si (f); + CHECK_MAX ("LONG_MIN"); + + mpf_clear (f); +} + + +void +check_limbdata (void) +{ +#define M GMP_NUMB_MAX + + static const struct { + mp_exp_t exp; + mp_size_t size; + mp_limb_t d[10]; + unsigned long want; + + } data[] = { + + /* in the comments here, a "_" indicates a digit (ie. limb) position not + included in the d data, and therefore zero */ + + { 0, 0, { 0 }, 0L }, /* 0 */ + + { 1, 1, { 1 }, 1L }, /* 1 */ + { 1, -1, { 1 }, -1L }, /* -1 */ + + { 0, 1, { 1 }, 0L }, /* .1 */ + { 0, -1, { 1 }, 0L }, /* -.1 */ + + { -1, 1, { 1 }, 0L }, /* ._1 */ + { -1, -1, { 1 }, 0L }, /* -._1 */ + + { -999, 1, { 1 }, 0L }, /* .___1 small */ + { MP_EXP_T_MIN, 1, { 1 }, 0L }, /* .____1 very small */ + + { 999, 1, { 1 }, 0L }, /* 1____. big */ + { MP_EXP_T_MAX, 1, { 1 }, 0L }, /* 1_____. very big */ + + { 1, 2, { 999, 2 }, 2L }, /* 2.9 */ + { 5, 8, { 7, 8, 9, 3, 0, 0, 0, 1 }, 3L }, /* 10003.987 */ + + { 2, 2, { M, M }, LONG_MAX }, /* FF. */ + { 2, 2, { M, M, M }, LONG_MAX }, /* FF.F */ + { 3, 3, { M, M, M }, LONG_MAX }, /* FFF. */ + +#if GMP_NUMB_BITS >= BITS_PER_ULONG + /* normal case, numb bigger than long */ + { 2, 1, { 1 }, 0L }, /* 1_. */ + { 2, 2, { 0, 1 }, 0L }, /* 10. */ + { 2, 2, { 999, 1 }, 999L }, /* 19. */ + { 3, 2, { 999, 1 }, 0L }, /* 19_. */ + +#else + /* nails case, numb smaller than long */ + { 2, 1, { 1 }, 1L << GMP_NUMB_BITS }, /* 1_. */ + { 3, 1, { 1 }, 0L }, /* 1__. */ + + { 2, 2, { 99, 1 }, 99L + (1L << GMP_NUMB_BITS) }, /* 19. */ + { 3, 2, { 1, 99 }, 1L << GMP_NUMB_BITS }, /* 91_. */ + { 3, 3, { 0, 1, 99 }, 1L << GMP_NUMB_BITS }, /* 910. */ + +#endif + }; + + mpf_t f; + unsigned long got; + int i; + mp_limb_t buf[20 + numberof(data[i].d)]; + + for (i = 0; i < numberof (data); i++) + { + refmpn_fill (buf, 10, CNST_LIMB(0xDEADBEEF)); + refmpn_copy (buf+10, data[i].d, ABS(data[i].size)); + refmpn_fill (buf+10+ABS(data[i].size), 10, CNST_LIMB(0xDEADBEEF)); + + PTR(f) = buf+10; + EXP(f) = data[i].exp; + SIZ(f) = data[i].size; + PREC(f) = numberof (data[i].d); + MPF_CHECK_FORMAT (f); + + got = mpf_get_si (f); + if (got != data[i].want) + { + printf ("mpf_get_si wrong at limb data[%d]\n", i); + mpf_trace (" f", f); + mpn_trace (" d", data[i].d, data[i].size); + printf (" size %ld\n", (long) data[i].size); + printf (" exp %ld\n", (long) data[i].exp); + printf (" got %lu (0x%lX)\n", got, got); + printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); + abort(); + } + } +} + + +int +main (void) +{ + tests_start (); + + check_data (); + check_max (); + check_limbdata (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-get_ui.c b/gmp/tests/mpf/t-get_ui.c new file mode 100644 index 0000000000..2950cadaa5 --- /dev/null +++ b/gmp/tests/mpf/t-get_ui.c @@ -0,0 +1,128 @@ +/* Exercise mpf_get_ui. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_limbdata (void) +{ +#define M GMP_NUMB_MAX + + static const struct { + mp_exp_t exp; + mp_size_t size; + mp_limb_t d[10]; + unsigned long want; + + } data[] = { + + /* in the comments here, a "_" indicates a digit (ie. limb) position not + included in the d data, and therefore zero */ + + { 0, 0, { 0 }, 0L }, /* 0 */ + + { 1, 1, { 1 }, 1L }, /* 1 */ + { 1, -1, { 1 }, 1L }, /* -1 */ + + { 0, 1, { 1 }, 0L }, /* .1 */ + { 0, -1, { 1 }, 0L }, /* -.1 */ + + { -1, 1, { 1 }, 0L }, /* ._1 */ + { -1, -1, { 1 }, 0L }, /* -._1 */ + + { -999, 1, { 1 }, 0L }, /* .___1 small */ + { MP_EXP_T_MIN, 1, { 1 }, 0L }, /* .____1 very small */ + + { 999, 1, { 1 }, 0L }, /* 1____. big */ + { MP_EXP_T_MAX, 1, { 1 }, 0L }, /* 1_____. very big */ + + { 1, 2, { 999, 2 }, 2L }, /* 2.9 */ + { 5, 8, { 7, 8, 9, 3, 0, 0, 0, 1 }, 3L }, /* 10003.987 */ + + { 2, 2, { M, M }, ULONG_MAX }, /* FF. */ + { 2, 2, { M, M, M }, ULONG_MAX }, /* FF.F */ + { 3, 3, { M, M, M }, ULONG_MAX }, /* FFF. */ + +#if GMP_NUMB_BITS >= BITS_PER_ULONG + /* normal case, numb bigger than long */ + { 2, 1, { 1 }, 0L }, /* 1_. */ + { 2, 2, { 0, 1 }, 0L }, /* 10. */ + { 2, 2, { 999, 1 }, 999L }, /* 19. */ + { 3, 2, { 999, 1 }, 0L }, /* 19_. */ + +#else + /* nails case, numb smaller than long */ + { 2, 1, { 1 }, 1L << GMP_NUMB_BITS }, /* 1_. */ + { 3, 1, { 1 }, 0L }, /* 1__. */ + + { 2, 2, { 99, 1 }, 99L + (1L << GMP_NUMB_BITS) }, /* 19. */ + { 3, 2, { 1, 99 }, 1L << GMP_NUMB_BITS }, /* 91_. */ + { 3, 3, { 0, 1, 99 }, 1L << GMP_NUMB_BITS }, /* 910. */ + +#endif + }; + + mpf_t f; + unsigned long got; + int i; + mp_limb_t buf[20 + numberof(data[i].d)]; + + for (i = 0; i < numberof (data); i++) + { + refmpn_fill (buf, 10, CNST_LIMB(0xDEADBEEF)); + refmpn_copy (buf+10, data[i].d, ABS(data[i].size)); + refmpn_fill (buf+10+ABS(data[i].size), 10, CNST_LIMB(0xDEADBEEF)); + + PTR(f) = buf+10; + EXP(f) = data[i].exp; + SIZ(f) = data[i].size; + PREC(f) = numberof (data[i].d); + MPF_CHECK_FORMAT (f); + + got = mpf_get_ui (f); + if (got != data[i].want) + { + printf ("mpf_get_ui wrong at limb data[%d]\n", i); + mpf_trace (" f", f); + mpn_trace (" d", data[i].d, data[i].size); + printf (" size %ld\n", (long) data[i].size); + printf (" exp %ld\n", (long) data[i].exp); + printf (" got %lu (0x%lX)\n", got, got); + printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); + abort(); + } + } +} + +int +main (void) +{ + tests_start (); + mp_trace_base = 16; + + check_limbdata (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-gsprec.c b/gmp/tests/mpf/t-gsprec.c new file mode 100644 index 0000000000..5a7615fc26 --- /dev/null +++ b/gmp/tests/mpf/t-gsprec.c @@ -0,0 +1,62 @@ +/* Test mpf_get_prec and mpf_set_prec. + +Copyright 2000, 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +void +check_consistency (void) +{ + mpf_t x; + unsigned long i, a, b; + + mpf_init (x); + + for (i = 1; i < 2000; i++) + { + mpf_set_prec (x, i); + a = mpf_get_prec (x); + mpf_set_prec (x, a); + b = mpf_get_prec (x); + if (a != b) + { + printf ("mpf_get_prec / mpf_set_prec inconsistent\n"); + printf (" set %lu gives %lu, but then set %lu gives %lu\n", + i, a, + a, b); + abort (); + } + } + + mpf_clear (x); +} + +int +main (void) +{ + tests_start (); + + check_consistency (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-inp_str.c b/gmp/tests/mpf/t-inp_str.c new file mode 100644 index 0000000000..38b54e6a0d --- /dev/null +++ b/gmp/tests/mpf/t-inp_str.c @@ -0,0 +1,192 @@ +/* Test mpf_inp_str. + +Copyright 2001, 2002 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#if HAVE_UNISTD_H +#include <unistd.h> /* for unlink */ +#endif + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +#define FILENAME "t-inp_str.tmp" + + +void +check_data (void) +{ + static const struct { + const char *inp; + int base; + const char *want; + int want_nread; + + } data[] = { + + { "0", 10, "0", 1 }, + + { "abc", 10, "0", 0 }, + { "ghi", 16, "0", 0 }, + + { "125", 10, "125", 3 }, + { "125e1", 10, "1250", 5 }, + { "12e+2", 10, "1200", 5 }, + { "125e-1", 10, "12.5", 6 }, + + { "ff", 16, "255", 2 }, + { "-ff", 16, "-255", 3 }, + { "FF", 16, "255", 2 }, + { "-FF", 16, "-255", 3 }, + + { "100", 16, "256", 3 }, + { "100@1", 16, "4096", 5 }, + { "100@10", 16, "4722366482869645213696", 6 }, + { "100@10", -16, "281474976710656", 6 }, + { "100@-1", 16, "16", 6 }, + { "10000000000000000@-10", 16, "1", 21 }, + { "10000000000@-10", -16, "1", 15 }, + + { "z", 36, "35", 1 }, + { "Z", 36, "35", 1 }, + { "z@1", 36, "1260", 3 }, + { "Z@1", 36, "1260", 3 }, + + { "0", 0, "0", 1 }, + }; + + mpf_t got, want; + long ftell_nread; + int i, pre, post, j, got_nread, want_nread; + FILE *fp; + + mpf_init (got); + mpf_init (want); + + for (i = 0; i < numberof (data); i++) + { + for (pre = 0; pre <= 3; pre++) + { + for (post = 0; post <= 2; post++) + { + mpf_set_str_or_abort (want, data[i].want, 10); + MPF_CHECK_FORMAT (want); + + /* create the file new each time to ensure its length is what + we want */ + fp = fopen (FILENAME, "w+"); + ASSERT_ALWAYS (fp != NULL); + for (j = 0; j < pre; j++) + putc (' ', fp); + fputs (data[i].inp, fp); + for (j = 0; j < post; j++) + putc (' ', fp); + fflush (fp); + ASSERT_ALWAYS (! ferror(fp)); + + rewind (fp); + got_nread = mpf_inp_str (got, fp, data[i].base); + + if (got_nread != 0) + { + ftell_nread = ftell (fp); + if (got_nread != ftell_nread) + { + printf ("mpf_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" got_nread %d\n", got_nread); + printf (" ftell_nread %ld\n", ftell_nread); + abort (); + } + } + + /* if data[i].inp is a whole string to read and there's no post + whitespace then expect to have EOF */ + if (post == 0 && data[i].want_nread == strlen(data[i].inp)) + { + int c = getc(fp); + if (c != EOF) + { + printf ("mpf_inp_str didn't read to EOF\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" c '%c' %#x\n", c, c); + abort (); + } + } + + /* only expect "pre" included in the count when non-zero */ + want_nread = data[i].want_nread; + if (want_nread != 0) + want_nread += pre; + + if (got_nread != want_nread) + { + printf ("mpf_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" got_nread %d\n", got_nread); + printf (" want_nread %d\n", want_nread); + abort (); + } + + MPF_CHECK_FORMAT (got); + + if (mpf_cmp (got, want) != 0) + { + printf ("mpf_inp_str wrong result\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + mpf_trace (" got ", got); + mpf_trace (" want", want); + abort (); + } + + ASSERT_ALWAYS (fclose (fp) == 0); + } + } + } + + mpf_clear (got); + mpf_clear (want); +} + +int +main (void) +{ + tests_start (); + + check_data (); + + unlink (FILENAME); + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-int_p.c b/gmp/tests/mpf/t-int_p.c new file mode 100644 index 0000000000..ea07668a1d --- /dev/null +++ b/gmp/tests/mpf/t-int_p.c @@ -0,0 +1,84 @@ +/* Test mpf_integer_p. + +Copyright 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +one (mpf_srcptr f, int want) +{ + int got; + got = mpf_integer_p (f); + if (got != want) + { + printf ("mpf_integer_p got %d want %d\n", got, want); + mpf_trace (" f", f); + abort (); + } +} + +void +all (mpf_ptr f, int want) +{ + one (f, want); + mpf_neg (f, f); + one (f, want); +} + +int +main (void) +{ + mpf_t f; + + tests_start (); + mpf_init2 (f, 200L); + + mpf_set_ui (f, 0L); + one (f, 1); + + mpf_set_ui (f, 1L); + all (f, 1); + + mpf_set_ui (f, 1L); + mpf_div_2exp (f, f, 1L); + all (f, 0); + + mpf_set_ui (f, 1L); + mpf_div_2exp (f, f, 5000L); + all (f, 0); + + mpf_set_ui (f, 1L); + mpf_mul_2exp (f, f, 5000L); + all (f, 1); + + mpf_set_str (f, "0.5", 10); + all (f, 0); + + mpf_set_ui (f, 1L); + mpf_div_ui (f, f, 3L); + all (f, 0); + + mpf_clear (f); + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-mul_ui.c b/gmp/tests/mpf/t-mul_ui.c new file mode 100644 index 0000000000..6a25c79477 --- /dev/null +++ b/gmp/tests/mpf/t-mul_ui.c @@ -0,0 +1,165 @@ +/* Exercise mpf_mul_ui. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_one (const char *desc, mpf_ptr got, mpf_srcptr u, unsigned long v) +{ + mp_size_t usize, usign; + mp_ptr wp; + mpf_t want; + + MPF_CHECK_FORMAT (got); + + /* this code not nailified yet */ + ASSERT_ALWAYS (BITS_PER_ULONG <= GMP_NUMB_BITS); + usign = SIZ (u); + usize = ABS (usign); + wp = refmpn_malloc_limbs (usize + 1); + wp[usize] = mpn_mul_1 (wp, PTR(u), usize, (mp_limb_t) v); + + PTR(want) = wp; + SIZ(want) = (usign >= 0 ? usize+1 : -(usize+1)); + EXP(want) = EXP(u) + 1; + refmpf_normalize (want); + + if (! refmpf_validate ("mpf_mul_ui", got, want)) + { + mp_trace_base = -16; + printf (" %s\n", desc); + mpf_trace (" u", u); + printf (" v %ld 0x%lX\n", v, v); + abort (); + } + + free (wp); +} + +void +check_rand (void) +{ + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + mpf_t got, u; + unsigned long prec, v; + int i; + + /* The nails code in mpf_mul_ui currently isn't exact, so suppress these + tests for now. */ + if (BITS_PER_ULONG > GMP_NUMB_BITS) + return; + + mpf_init (got); + mpf_init (u); + + for (i = 0; i < 200; i++) + { + /* got precision */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (got, prec); + + /* u precision */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (u, prec); + + /* u, possibly negative */ + mpf_random2 (u, PREC(u), (mp_exp_t) 20); + if (gmp_urandomb_ui (rands, 1L)) + mpf_neg (u, u); + + /* v, 0 to BITS_PER_ULONG bits (inclusive) */ + prec = gmp_urandomm_ui (rands, BITS_PER_ULONG+1); + v = gmp_urandomb_ui (rands, prec); + + if ((i % 2) == 0) + { + /* separate */ + mpf_mul_ui (got, u, v); + check_one ("separate", got, u, v); + } + else + { + /* overlap */ + prec = refmpf_set_overlap (got, u); + mpf_mul_ui (got, got, v); + check_one ("overlap src==dst", got, u, v); + + mpf_set_prec_raw (got, prec); + } + } + + mpf_clear (got); + mpf_clear (u); +} + +void +check_various (void) +{ + mpf_t u, got, want; + const char *s; + + mpf_init2 (u, 2*8*sizeof(long)); + mpf_init2 (got, 2*8*sizeof(long)); + mpf_init2 (want, 2*8*sizeof(long)); + + s = "0 * ULONG_MAX"; + mpf_set_ui (u, 0L); + mpf_mul_ui (got, u, ULONG_MAX); + MPF_CHECK_FORMAT (got); + mpf_set_ui (want, 0L); + if (mpf_cmp (got, want) != 0) + { + error: + printf ("Wrong result from %s\n", s); + mpf_trace ("u ", u); + mpf_trace ("got ", got); + mpf_trace ("want", want); + abort (); + } + + s = "1 * ULONG_MAX"; + mpf_set_ui (u, 1L); + mpf_mul_ui (got, u, ULONG_MAX); + MPF_CHECK_FORMAT (got); + mpf_set_ui (want, ULONG_MAX); + if (mpf_cmp (got, want) != 0) + goto error; + + mpf_clear (u); + mpf_clear (got); + mpf_clear (want); +} + +int +main (void) +{ + tests_start (); + + check_various (); + check_rand (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-muldiv.c b/gmp/tests/mpf/t-muldiv.c new file mode 100644 index 0000000000..2751bb9dad --- /dev/null +++ b/gmp/tests/mpf/t-muldiv.c @@ -0,0 +1,159 @@ +/* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui. + +Copyright 1996, 2000, 2001, 2003 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 16 +#endif + +int +main (int argc, char **argv) +{ + mp_size_t size; + mp_exp_t exp; + int reps = 10000; + int i; + mpf_t u, v, w, x; + mp_size_t bprec = SIZE * GMP_LIMB_BITS; + mpf_t rerr, limit_rerr; + unsigned long ulimb, vlimb; + int single_flag; + + tests_start (); + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init (rerr); + mpf_init (limit_rerr); + + mpf_init (u); + mpf_init (v); + mpf_init (w); + mpf_init (x); + + for (i = 0; i < reps; i++) + { + mp_size_t res_prec; + + res_prec = urandom () % bprec + 1; + mpf_set_prec (w, res_prec); + mpf_set_prec (x, res_prec); + + mpf_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, res_prec - 1); + + single_flag = 0; + + if ((urandom () & 1) != 0) + { + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (u, size, exp); + } + else + { + ulimb = urandom (); + mpf_set_ui (u, ulimb); + single_flag = 1; + } + + if ((urandom () & 1) != 0) + { + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (v, size, exp); + } + else + { + vlimb = urandom (); + mpf_set_ui (v, vlimb); + single_flag = 2; + } + + if (mpf_sgn (v) == 0) + continue; + + mpf_div (w, u, v); + mpf_mul (x, w, v); + mpf_reldiff (rerr, u, x); + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf (" x = "); mpf_dump (x); + printf (" w = "); mpf_dump (w); + abort (); + } + + if (single_flag == 2) + { + mpf_div_ui (x, u, vlimb); + mpf_reldiff (rerr, w, x); + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf (" x = "); mpf_dump (x); + printf (" w = "); mpf_dump (w); + abort (); + } + } + + if (single_flag == 1) + { + mpf_ui_div (x, ulimb, v); + mpf_reldiff (rerr, w, x); + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf (" x = "); mpf_dump (x); + printf (" w = "); mpf_dump (w); + abort (); + } + } + } + + mpf_clear (rerr); + mpf_clear (limit_rerr); + + mpf_clear (u); + mpf_clear (v); + mpf_clear (w); + mpf_clear (x); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-set.c b/gmp/tests/mpf/t-set.c new file mode 100644 index 0000000000..3846d501a1 --- /dev/null +++ b/gmp/tests/mpf/t-set.c @@ -0,0 +1,113 @@ +/* Test mpf_set, mpf_init_set. + +Copyright 2004, 2012 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +void +check_reuse (void) +{ + /* Try mpf_set(f,f) when f is bigger than prec. In the past this had + resulted in an MPN_COPY with invalid operand overlap. */ + mpf_t f; + mp_size_t limbs = 20; + unsigned long bits = limbs * GMP_NUMB_BITS; + mpf_init2 (f, bits); + refmpf_fill (f, limbs, GMP_NUMB_MAX); + mpf_set_prec_raw (f, bits / 2); + mpf_set (f, f); + MPF_CHECK_FORMAT (f); + mpf_set_prec_raw (f, bits); + mpf_clear (f); +} + +void +check_random (long reps) +{ + unsigned long test; + gmp_randstate_ptr rands; + mpf_t a, b; + mpz_t z; + int precbits; + +#define PRECBITS 10 + + rands = RANDS; + + mpz_init (z); + mpf_init2 (a, 1 << PRECBITS); + + for (test = 0; test < reps; test++) + { + mpz_urandomb (z, rands, PRECBITS + 1); + precbits = mpz_get_ui (z) + 1; + mpz_urandomb (z, rands, precbits); + mpz_setbit (z, precbits - 1); /* make sure msb is set */ + mpf_set_z (a, z); + if (precbits & 1) + mpf_neg (a, a); + mpz_urandomb (z, rands, PRECBITS); + mpf_div_2exp (a, a, mpz_get_ui (z) + 1); + mpz_urandomb (z, rands, PRECBITS); + precbits -= mpz_get_ui (z); + if (precbits <= 0) + precbits = 1 - precbits; + mpf_set_default_prec (precbits); + + mpf_init_set (b, a); + MPF_CHECK_FORMAT (b); + if (!mpf_eq (a, b, precbits)) + { + printf ("mpf_init_set wrong.\n"); + abort(); + } + + mpf_set_ui (b, 0); + mpf_set (b, a); + MPF_CHECK_FORMAT (b); + if (!mpf_eq (a, b, precbits)) + { + printf ("mpf_set wrong.\n"); + abort(); + } + + mpf_clear (b); + } + + mpf_clear (a); + mpz_clear (z); +} + +int +main (int argc, char *argv[]) +{ + long reps = 10000; + + tests_start (); + TESTS_REPS (reps, argv, argc); + + check_reuse (); + check_random (reps); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-set_q.c b/gmp/tests/mpf/t-set_q.c new file mode 100644 index 0000000000..2c48b277da --- /dev/null +++ b/gmp/tests/mpf/t-set_q.c @@ -0,0 +1,127 @@ +/* Test mpf_set_q. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_one (mpf_ptr got, mpq_srcptr q) +{ + mpf_t n, d; + + mpf_set_q (got, q); + + PTR(n) = PTR(&q->_mp_num); + SIZ(n) = SIZ(&q->_mp_num); + EXP(n) = ABSIZ(&q->_mp_num); + + PTR(d) = PTR(&q->_mp_den); + SIZ(d) = SIZ(&q->_mp_den); + EXP(d) = ABSIZ(&q->_mp_den); + + if (! refmpf_validate_division ("mpf_set_q", got, n, d)) + { + mp_trace_base = -16; + mpq_trace (" q", q); + abort (); + } +} + +void +check_rand (void) +{ + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long prec; + mpf_t got; + mpq_t q; + int i; + + mpf_init (got); + mpq_init (q); + + for (i = 0; i < 400; i++) + { + /* result precision */ + prec = min_prec + gmp_urandomm_ui (rands, 20L); + refmpf_set_prec_limbs (got, prec); + + /* num */ + prec = gmp_urandomm_ui (rands, 20L * GMP_NUMB_BITS); + mpz_rrandomb (mpq_numref(q), rands, prec); + + /* possibly negative num */ + if (gmp_urandomb_ui (rands, 1L)) + mpz_neg (mpq_numref(q), mpq_numref(q)); + + /* den, non-zero */ + do { + prec = gmp_urandomm_ui (rands, 20L * GMP_NUMB_BITS); + mpz_rrandomb (mpq_denref(q), rands, prec); + } while (mpz_sgn (mpq_denref(q)) <= 0); + + check_one (got, q); + } + + mpf_clear (got); + mpq_clear (q); +} + +void +check_various (void) +{ + mpf_t got; + mpq_t q; + + mpf_init (got); + mpq_init (q); + + /* 1/1 == 1 */ + mpf_set_prec (got, 20L); + mpq_set_ui (q, 1L, 1L); + mpf_set_q (got, q); + MPF_CHECK_FORMAT (got); + ASSERT_ALWAYS (mpf_cmp_ui (got, 1L) == 0); + + /* 1/(2^n+1), a case where truncating the divisor would be wrong */ + mpf_set_prec (got, 500L); + mpq_set_ui (q, 1L, 1L); + mpz_mul_2exp (mpq_denref(q), mpq_denref(q), 800L); + mpz_add_ui (mpq_denref(q), mpq_denref(q), 1L); + check_one (got, q); + + mpf_clear (got); + mpq_clear (q); +} + +int +main (void) +{ + tests_start (); + + check_various (); + check_rand (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-set_si.c b/gmp/tests/mpf/t-set_si.c new file mode 100644 index 0000000000..8975be7bed --- /dev/null +++ b/gmp/tests/mpf/t-set_si.c @@ -0,0 +1,91 @@ +/* Test mpf_set_si and mpf_init_set_si. + +Copyright 2000, 2001, 2003 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +void +check_data (void) +{ + static const struct { + long x; + mp_size_t want_size; + mp_limb_t want_data[2]; + } data[] = { + + { 0L, 0 }, + { 1L, 1, { 1 } }, + { -1L, -1, { 1 } }, + +#if GMP_NUMB_BITS >= BITS_PER_ULONG + { LONG_MAX, 1, { LONG_MAX, 0 } }, + { -LONG_MAX, -1, { LONG_MAX, 0 } }, + { LONG_HIGHBIT, -1, { ULONG_HIGHBIT, 0 } }, +#else + { LONG_MAX, 2, { LONG_MAX & GMP_NUMB_MASK, LONG_MAX >> GMP_NUMB_BITS } }, + { -LONG_MAX, -2, { LONG_MAX & GMP_NUMB_MASK, LONG_MAX >> GMP_NUMB_BITS }}, + { LONG_HIGHBIT, -2, { 0, ULONG_HIGHBIT >> GMP_NUMB_BITS } }, +#endif + }; + + mpf_t x; + int i; + + for (i = 0; i < numberof (data); i++) + { + mpf_init (x); + mpf_set_si (x, data[i].x); + MPF_CHECK_FORMAT (x); + if (x->_mp_size != data[i].want_size + || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, + ABS (data[i].want_size)) != 0 + || x->_mp_exp != ABS (data[i].want_size)) + { + printf ("mpf_set_si wrong on data[%d]\n", i); + abort(); + } + mpf_clear (x); + + mpf_init_set_si (x, data[i].x); + MPF_CHECK_FORMAT (x); + if (x->_mp_size != data[i].want_size + || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, + ABS (data[i].want_size)) != 0 + || x->_mp_exp != ABS (data[i].want_size)) + { + printf ("mpf_init_set_si wrong on data[%d]\n", i); + abort(); + } + mpf_clear (x); + } +} + +int +main (void) +{ + tests_start (); + + check_data (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-set_ui.c b/gmp/tests/mpf/t-set_ui.c new file mode 100644 index 0000000000..8c49e91e67 --- /dev/null +++ b/gmp/tests/mpf/t-set_ui.c @@ -0,0 +1,90 @@ +/* Test mpf_set_ui and mpf_init_set_ui. + +Copyright 2000, 2001, 2003 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +void +check_data (void) +{ + static const struct { + unsigned long x; + mp_size_t want_size; + mp_limb_t want_data[2]; + } data[] = { + + { 0L, 0 }, + { 1L, 1, { 1 } }, + +#if GMP_NUMB_BITS >= BITS_PER_ULONG + { ULONG_MAX, 1, { ULONG_MAX, 0 } }, + { ULONG_HIGHBIT, 1, { ULONG_HIGHBIT, 0 } }, +#else + { ULONG_MAX, 2, { ULONG_MAX & GMP_NUMB_MASK, + ULONG_MAX >> GMP_NUMB_BITS } }, + { ULONG_HIGHBIT, 2, { 0, + ULONG_HIGHBIT >> GMP_NUMB_BITS } }, +#endif + }; + + mpf_t x; + int i; + + for (i = 0; i < numberof (data); i++) + { + mpf_init (x); + mpf_set_ui (x, data[i].x); + MPF_CHECK_FORMAT (x); + if (x->_mp_size != data[i].want_size + || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, + ABS (data[i].want_size)) != 0 + || x->_mp_exp != ABS (data[i].want_size)) + { + printf ("mpf_set_ui wrong on data[%d]\n", i); + abort(); + } + mpf_clear (x); + + mpf_init_set_ui (x, data[i].x); + MPF_CHECK_FORMAT (x); + if (x->_mp_size != data[i].want_size + || refmpn_cmp_allowzero (x->_mp_d, data[i].want_data, + ABS (data[i].want_size)) != 0 + || x->_mp_exp != ABS (data[i].want_size)) + { + printf ("mpf_init_set_ui wrong on data[%d]\n", i); + abort(); + } + mpf_clear (x); + } +} + +int +main (void) +{ + tests_start (); + + check_data (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-sqrt.c b/gmp/tests/mpf/t-sqrt.c new file mode 100644 index 0000000000..16a823d9a4 --- /dev/null +++ b/gmp/tests/mpf/t-sqrt.c @@ -0,0 +1,194 @@ +/* Test mpf_sqrt, mpf_mul. + +Copyright 1996, 2001, 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 16 +#endif + +void +check_rand1 (int argc, char **argv) +{ + mp_size_t size; + mp_exp_t exp; + int reps = 20000; + int i; + mpf_t x, y, y2; + mp_size_t bprec = 100; + mpf_t rerr, max_rerr, limit_rerr; + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, bprec); +#if VERBOSE + mpf_dump (limit_rerr); +#endif + mpf_init (rerr); + mpf_init_set_ui (max_rerr, 0); + + mpf_init (x); + mpf_init (y); + mpf_init (y2); + for (i = 0; i < reps; i++) + { + size = urandom () % SIZE; + exp = urandom () % SIZE; + mpf_random2 (x, size, exp); + + mpf_sqrt (y, x); + MPF_CHECK_FORMAT (y); + mpf_mul (y2, y, y); + + mpf_reldiff (rerr, x, y2); + if (mpf_cmp (rerr, max_rerr) > 0) + { + mpf_set (max_rerr, rerr); +#if VERBOSE + mpf_dump (max_rerr); +#endif + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR after %d tests\n", i); + printf (" x = "); mpf_dump (x); + printf (" y = "); mpf_dump (y); + printf (" y2 = "); mpf_dump (y2); + printf (" rerr = "); mpf_dump (rerr); + printf (" limit_rerr = "); mpf_dump (limit_rerr); + printf ("in hex:\n"); + mp_trace_base = 16; + mpf_trace (" x ", x); + mpf_trace (" y ", y); + mpf_trace (" y2 ", y2); + mpf_trace (" rerr ", rerr); + mpf_trace (" limit_rerr", limit_rerr); + abort (); + } + } + } + + mpf_clear (limit_rerr); + mpf_clear (rerr); + mpf_clear (max_rerr); + + mpf_clear (x); + mpf_clear (y); + mpf_clear (y2); +} + +void +check_rand2 (void) +{ + unsigned long max_prec = 20; + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long x_prec, r_prec; + mpf_t x, r, s; + int i; + + mpf_init (x); + mpf_init (r); + mpf_init (s); + refmpf_set_prec_limbs (s, 2*max_prec+10); + + for (i = 0; i < 500; i++) + { + /* input precision */ + x_prec = gmp_urandomm_ui (rands, max_prec-min_prec) + min_prec; + refmpf_set_prec_limbs (x, x_prec); + + /* result precision */ + r_prec = gmp_urandomm_ui (rands, max_prec-min_prec) + min_prec; + refmpf_set_prec_limbs (r, r_prec); + + mpf_random2 (x, x_prec, 1000); + + mpf_sqrt (r, x); + MPF_CHECK_FORMAT (r); + + /* Expect to prec limbs of result. + In the current implementation there's no stripping of low zero + limbs in mpf_sqrt, so size should be exactly prec. */ + if (SIZ(r) != r_prec) + { + printf ("mpf_sqrt wrong number of result limbs\n"); + mpf_trace (" x", x); + mpf_trace (" r", r); + printf (" r_prec=%lu\n", r_prec); + printf (" SIZ(r) %ld\n", (long) SIZ(r)); + printf (" PREC(r) %ld\n", (long) PREC(r)); + abort (); + } + + /* Must have r^2 <= x, since r has been truncated. */ + mpf_mul (s, r, r); + if (! (mpf_cmp (s, x) <= 0)) + { + printf ("mpf_sqrt result too big\n"); + mpf_trace (" x", x); + printf (" r_prec=%lu\n", r_prec); + mpf_trace (" r", r); + mpf_trace (" s", s); + abort (); + } + + /* Must have (r+ulp)^2 > x, or else r is too small. */ + refmpf_add_ulp (r); + mpf_mul (s, r, r); + if (! (mpf_cmp (s, x) > 0)) + { + printf ("mpf_sqrt result too small\n"); + mpf_trace (" x", x); + printf (" r_prec=%lu\n", r_prec); + mpf_trace (" r+ulp", r); + mpf_trace (" s", s); + abort (); + } + } + + mpf_clear (x); + mpf_clear (r); + mpf_clear (s); +} + +int +main (int argc, char **argv) +{ + tests_start (); + mp_trace_base = -16; + + check_rand1 (argc, argv); + check_rand2 (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-sqrt_ui.c b/gmp/tests/mpf/t-sqrt_ui.c new file mode 100644 index 0000000000..c9233da29c --- /dev/null +++ b/gmp/tests/mpf/t-sqrt_ui.c @@ -0,0 +1,113 @@ +/* Test mpf_sqrt_ui. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_rand (void) +{ + unsigned long max_prec = 15; + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long x, prec; + mpf_t r, s; + int i; + + mpf_init (r); + mpf_init (s); + refmpf_set_prec_limbs (s, 2*max_prec+10); + + for (i = 0; i < 50; i++) + { + /* input, a random non-zero ulong, exponentially distributed */ + do { + x = gmp_urandomb_ui (rands, + gmp_urandomm_ui (rands, BITS_PER_ULONG) + 1); + } while (x == 0); + + /* result precision */ + prec = gmp_urandomm_ui (rands, max_prec-min_prec) + min_prec; + refmpf_set_prec_limbs (r, prec); + + mpf_sqrt_ui (r, x); + MPF_CHECK_FORMAT (r); + + /* Expect to prec limbs of result. + In the current implementation there's no stripping of low zero + limbs in mpf_sqrt_ui, not even on perfect squares, so size should + be exactly prec. */ + if (SIZ(r) != prec) + { + printf ("mpf_sqrt_ui result not enough result limbs\n"); + printf (" x=%lu\n", x); + printf (" want prec=%lu\n", prec); + mpf_trace (" r", r); + printf (" r size %ld\n", (long) SIZ(r)); + printf (" r prec %ld\n", (long) PREC(r)); + abort (); + } + + /* Must have r^2 <= x, since r has been truncated. */ + mpf_mul (s, r, r); + if (! (mpf_cmp_ui (s, x) <= 0)) + { + printf ("mpf_sqrt_ui result too big\n"); + printf (" x=%lu\n", x); + printf (" want prec=%lu\n", prec); + mpf_trace (" r", r); + mpf_trace (" s", s); + abort (); + } + + /* Must have (r+ulp)^2 > x. + No overflow from refmpf_add_ulp since r is only prec limbs. */ + refmpf_add_ulp (r); + mpf_mul (s, r, r); + if (! (mpf_cmp_ui (s, x) > 0)) + { + printf ("mpf_sqrt_ui result too small\n"); + printf (" x=%lu\n", x); + printf (" want prec=%lu\n", prec); + mpf_trace (" r+ulp", r); + mpf_trace (" s", s); + abort (); + } + } + + mpf_clear (r); + mpf_clear (s); +} + +int +main (int argc, char **argv) +{ + tests_start (); + mp_trace_base = -16; + + check_rand (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-sub.c b/gmp/tests/mpf/t-sub.c new file mode 100644 index 0000000000..66281f4243 --- /dev/null +++ b/gmp/tests/mpf/t-sub.c @@ -0,0 +1,206 @@ +/* Test mpf_sub. + +Copyright 1996, 2001, 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +#ifndef SIZE +#define SIZE 16 +#endif + +void +check_rand (int argc, char **argv) +{ + mp_size_t size; + mp_exp_t exp; + int reps = 20000; + int i; + mpf_t u, v, w, wref; + mp_size_t bprec = 100; + mpf_t rerr, max_rerr, limit_rerr; + + if (argc > 1) + { + reps = strtol (argv[1], 0, 0); + if (argc > 2) + bprec = strtol (argv[2], 0, 0); + } + + mpf_set_default_prec (bprec); + + mpf_init_set_ui (limit_rerr, 1); + mpf_div_2exp (limit_rerr, limit_rerr, bprec); +#if VERBOSE + mpf_dump (limit_rerr); +#endif + mpf_init (rerr); + mpf_init_set_ui (max_rerr, 0); + + mpf_init (u); + mpf_init (v); + mpf_init (w); + mpf_init (wref); + for (i = 0; i < reps; i++) + { + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (u, size, exp); + + size = urandom () % (2 * SIZE) - SIZE; + exp = urandom () % SIZE; + mpf_random2 (v, size, exp); + + if ((urandom () & 1) != 0) + mpf_add_ui (u, v, 1); + else if ((urandom () & 1) != 0) + mpf_sub_ui (u, v, 1); + + mpf_sub (w, u, v); + refmpf_sub (wref, u, v); + + mpf_reldiff (rerr, w, wref); + if (mpf_cmp (rerr, max_rerr) > 0) + { + mpf_set (max_rerr, rerr); +#if VERBOSE + mpf_dump (max_rerr); +#endif + if (mpf_cmp (rerr, limit_rerr) > 0) + { + printf ("ERROR after %d tests\n", i); + printf (" u = "); mpf_dump (u); + printf (" v = "); mpf_dump (v); + printf ("wref = "); mpf_dump (wref); + printf (" w = "); mpf_dump (w); + abort (); + } + } + } + + mpf_clear (limit_rerr); + mpf_clear (rerr); + mpf_clear (max_rerr); + + mpf_clear (u); + mpf_clear (v); + mpf_clear (w); + mpf_clear (wref); +} + + +void +check_data (void) +{ + static const struct { + struct { + int exp, size; + mp_limb_t d[10]; + } x, y, want; + + } data[] = { + { { 123, 2, { 8, 9 } }, { 123, 1, { 9 } }, { 122, 1, { 8 } } }, + + /* f - f == 0, various sizes. + These exercise a past problem (gmp 4.1.3 and earlier) where the + result exponent was not zeroed on a zero result like this. */ + { { 0, 0 }, { 0, 0 }, { 0, 0 } }, + { { 99, 1, { 1 } }, { 99, 1, { 1 } }, { 0, 0 } }, + { { 99, 2, { 123, 456 } }, { 99, 2, { 123, 456 } }, { 0, 0 } }, + { { 99, 3, { 123, 456, 789 } }, { 99, 3, { 123, 456, 789 } }, { 0, 0 } }, + + /* High limbs cancel, leaving just the low limbs of the longer operand. + This exercises a past problem (gmp 4.1.3 and earlier) where high zero + limbs on the remainder were not stripped before truncating to the + destination, causing loss of precision. */ + { { 123, 2, { 8, 9 } }, { 123, 1, { 9 } }, { 122, 1, { 8 } } }, + { { 123, 3, { 8, 0, 9 } }, { 123, 1, { 9 } }, { 121, 1, { 8 } } }, + { { 123, 4, { 8, 0, 0, 9 } }, { 123, 1, { 9 } }, { 120, 1, { 8 } } }, + { { 123, 5, { 8, 0, 0, 0, 9 } }, { 123, 1, { 9 } }, { 119, 1, { 8 } } }, + { { 123, 6, { 8, 0, 0, 0, 0, 9 } }, { 123, 1, { 9 } }, { 118, 1, { 8 } } }, + + }; + + mpf_t x, y, got, want; + int i, swap; + + mp_trace_base = 16; + mpf_init (got); + + for (i = 0; i < numberof (data); i++) + { + for (swap = 0; swap <= 1; swap++) + { + PTR(x) = (mp_ptr) data[i].x.d; + SIZ(x) = data[i].x.size; + EXP(x) = data[i].x.exp; + PREC(x) = numberof (data[i].x.d); + MPF_CHECK_FORMAT (x); + + PTR(y) = (mp_ptr) data[i].y.d; + SIZ(y) = data[i].y.size; + EXP(y) = data[i].y.exp; + PREC(y) = numberof (data[i].y.d); + MPF_CHECK_FORMAT (y); + + PTR(want) = (mp_ptr) data[i].want.d; + SIZ(want) = data[i].want.size; + EXP(want) = data[i].want.exp; + PREC(want) = numberof (data[i].want.d); + MPF_CHECK_FORMAT (want); + + if (swap) + { + mpf_swap (x, y); + SIZ(want) = - SIZ(want); + } + + mpf_sub (got, x, y); +/* MPF_CHECK_FORMAT (got); */ + + if (mpf_cmp (got, want) != 0) + { + printf ("check_data() wrong result at data[%d] (operands%s swapped)\n", i, swap ? "" : " not"); + mpf_trace ("x ", x); + mpf_trace ("y ", y); + mpf_trace ("got ", got); + mpf_trace ("want", want); + abort (); + } + } + } + + mpf_clear (got); +} + + +int +main (int argc, char **argv) +{ + tests_start (); + + check_data (); + check_rand (argc, argv); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-trunc.c b/gmp/tests/mpf/t-trunc.c new file mode 100644 index 0000000000..2eef414b00 --- /dev/null +++ b/gmp/tests/mpf/t-trunc.c @@ -0,0 +1,271 @@ +/* Test mpf_trunc, mpf_ceil, mpf_floor. + +Copyright 2001, 2002 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_print (mpf_srcptr src, mpf_srcptr got, mpf_srcptr want) +{ + mp_trace_base = 16; + mpf_trace ("src ", src); + mpf_trace ("got ", got); + mpf_trace ("want", want); + + printf ("got size=%d exp=%ld\n", SIZ(got), EXP(got)); + mpn_trace (" limbs=", PTR(got), (mp_size_t) ABSIZ(got)); + + printf ("want size=%d exp=%ld\n", SIZ(want), EXP(want)); + mpn_trace (" limbs=", PTR(want), (mp_size_t) ABSIZ(want)); +} + +void +check_one (mpf_srcptr src, mpf_srcptr trunc, mpf_srcptr ceil, mpf_srcptr floor) +{ + mpf_t got; + + mpf_init2 (got, mpf_get_prec (trunc)); + ASSERT_ALWAYS (PREC(got) == PREC(trunc)); + ASSERT_ALWAYS (PREC(got) == PREC(ceil)); + ASSERT_ALWAYS (PREC(got) == PREC(floor)); + +#define CHECK_SEP(name, fun, want) \ + mpf_set_ui (got, 54321L); /* initial junk */ \ + fun (got, src); \ + MPF_CHECK_FORMAT (got); \ + if (mpf_cmp (got, want) != 0) \ + { \ + printf ("%s wrong\n", name); \ + check_print (src, got, want); \ + abort (); \ + } + + CHECK_SEP ("mpf_trunc", mpf_trunc, trunc); + CHECK_SEP ("mpf_ceil", mpf_ceil, ceil); + CHECK_SEP ("mpf_floor", mpf_floor, floor); + +#define CHECK_INPLACE(name, fun, want) \ + mpf_set (got, src); \ + fun (got, got); \ + MPF_CHECK_FORMAT (got); \ + if (mpf_cmp (got, want) != 0) \ + { \ + printf ("%s wrong\n", name); \ + check_print (src, got, want); \ + abort (); \ + } + + CHECK_INPLACE ("mpf_trunc", mpf_trunc, trunc); + + /* Can't do these unconditionally in case truncation by mpf_set strips + some low non-zero limbs which would have rounded the result. */ + if (ABSIZ(src) <= PREC(trunc)+1) + { + CHECK_INPLACE ("mpf_ceil", mpf_ceil, ceil); + CHECK_INPLACE ("mpf_floor", mpf_floor, floor); + } + + mpf_clear (got); +} + +void +check_all (mpf_ptr src, mpf_ptr trunc, mpf_ptr ceil, mpf_ptr floor) +{ + /* some of these values are generated with direct field assignments */ + MPF_CHECK_FORMAT (src); + MPF_CHECK_FORMAT (trunc); + MPF_CHECK_FORMAT (ceil); + MPF_CHECK_FORMAT (floor); + + check_one (src, trunc, ceil, floor); + + mpf_neg (src, src); + mpf_neg (trunc, trunc); + mpf_neg (ceil, ceil); + mpf_neg (floor, floor); + check_one (src, trunc, floor, ceil); +} + +void +check_various (void) +{ + mpf_t src, trunc, ceil, floor; + int n, i; + + mpf_init2 (src, 512L); + mpf_init2 (trunc, 256L); + mpf_init2 (ceil, 256L); + mpf_init2 (floor, 256L); + + /* 0 */ + mpf_set_ui (src, 0L); + mpf_set_ui (trunc, 0L); + mpf_set_ui (ceil, 0L); + mpf_set_ui (floor, 0L); + check_all (src, trunc, ceil, floor); + + /* 1 */ + mpf_set_ui (src, 1L); + mpf_set_ui (trunc, 1L); + mpf_set_ui (ceil, 1L); + mpf_set_ui (floor, 1L); + check_all (src, trunc, ceil, floor); + + /* 2^1024 */ + mpf_set_ui (src, 1L); + mpf_mul_2exp (src, src, 1024L); + mpf_set (trunc, src); + mpf_set (ceil, src); + mpf_set (floor, src); + check_all (src, trunc, ceil, floor); + + /* 1/2^1024, fraction only */ + mpf_set_ui (src, 1L); + mpf_div_2exp (src, src, 1024L); + mpf_set_si (trunc, 0L); + mpf_set_si (ceil, 1L); + mpf_set_si (floor, 0L); + check_all (src, trunc, ceil, floor); + + /* 1/2 */ + mpf_set_ui (src, 1L); + mpf_div_2exp (src, src, 1L); + mpf_set_si (trunc, 0L); + mpf_set_si (ceil, 1L); + mpf_set_si (floor, 0L); + check_all (src, trunc, ceil, floor); + + /* 123+1/2^64 */ + mpf_set_ui (src, 1L); + mpf_div_2exp (src, src, 64L); + mpf_add_ui (src, src, 123L); + mpf_set_si (trunc, 123L); + mpf_set_si (ceil, 124L); + mpf_set_si (floor, 123L); + check_all (src, trunc, ceil, floor); + + /* integer of full prec+1 limbs, unchanged */ + n = PREC(trunc)+1; + ASSERT_ALWAYS (n <= PREC(src)+1); + EXP(src) = n; + SIZ(src) = n; + for (i = 0; i < SIZ(src); i++) + PTR(src)[i] = i+100; + mpf_set (trunc, src); + mpf_set (ceil, src); + mpf_set (floor, src); + check_all (src, trunc, ceil, floor); + + /* full prec+1 limbs, 1 trimmed for integer */ + n = PREC(trunc)+1; + ASSERT_ALWAYS (n <= PREC(src)+1); + EXP(src) = n-1; + SIZ(src) = n; + for (i = 0; i < SIZ(src); i++) + PTR(src)[i] = i+200; + EXP(trunc) = n-1; + SIZ(trunc) = n-1; + for (i = 0; i < SIZ(trunc); i++) + PTR(trunc)[i] = i+201; + mpf_set (floor, trunc); + mpf_add_ui (ceil, trunc, 1L); + check_all (src, trunc, ceil, floor); + + /* prec+3 limbs, 2 trimmed for size */ + n = PREC(trunc)+3; + ASSERT_ALWAYS (n <= PREC(src)+1); + EXP(src) = n; + SIZ(src) = n; + for (i = 0; i < SIZ(src); i++) + PTR(src)[i] = i+300; + EXP(trunc) = n; + SIZ(trunc) = n-2; + for (i = 0; i < SIZ(trunc); i++) + PTR(trunc)[i] = i+302; + mpf_set (floor, trunc); + mpf_set (ceil, trunc); + PTR(ceil)[0]++; + check_all (src, trunc, ceil, floor); + + /* prec+4 limbs, 2 trimmed for size, 1 trimmed for integer */ + n = PREC(trunc)+4; + ASSERT_ALWAYS (n <= PREC(src)+1); + EXP(src) = n-1; + SIZ(src) = n; + for (i = 0; i < SIZ(src); i++) + PTR(src)[i] = i+400; + EXP(trunc) = n-1; + SIZ(trunc) = n-3; + for (i = 0; i < SIZ(trunc); i++) + PTR(trunc)[i] = i+403; + mpf_set (floor, trunc); + mpf_set (ceil, trunc); + PTR(ceil)[0]++; + check_all (src, trunc, ceil, floor); + + /* F.F, carry out of ceil */ + EXP(src) = 1; + SIZ(src) = 2; + PTR(src)[0] = GMP_NUMB_MAX; + PTR(src)[1] = GMP_NUMB_MAX; + EXP(trunc) = 1; + SIZ(trunc) = 1; + PTR(trunc)[0] = GMP_NUMB_MAX; + mpf_set (floor, trunc); + EXP(ceil) = 2; + SIZ(ceil) = 1; + PTR(ceil)[0] = 1; + check_all (src, trunc, ceil, floor); + + /* FF.F, carry out of ceil */ + EXP(src) = 2; + SIZ(src) = 3; + PTR(src)[0] = GMP_NUMB_MAX; + PTR(src)[1] = GMP_NUMB_MAX; + PTR(src)[2] = GMP_NUMB_MAX; + EXP(trunc) = 2; + SIZ(trunc) = 2; + PTR(trunc)[0] = GMP_NUMB_MAX; + PTR(trunc)[1] = GMP_NUMB_MAX; + mpf_set (floor, trunc); + EXP(ceil) = 3; + SIZ(ceil) = 1; + PTR(ceil)[0] = 1; + check_all (src, trunc, ceil, floor); + + mpf_clear (src); + mpf_clear (trunc); + mpf_clear (ceil); + mpf_clear (floor); +} + +int +main (void) +{ + tests_start (); + + check_various (); + + tests_end (); + exit (0); +} diff --git a/gmp/tests/mpf/t-ui_div.c b/gmp/tests/mpf/t-ui_div.c new file mode 100644 index 0000000000..3024efdbc4 --- /dev/null +++ b/gmp/tests/mpf/t-ui_div.c @@ -0,0 +1,152 @@ +/* Test mpf_ui_div. + +Copyright 2004 Free Software Foundation, Inc. + +This file is part of the GNU MP Library test suite. + +The GNU MP Library test suite is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. + +The GNU MP Library test suite is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with +the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + + +void +check_one (const char *desc, mpf_ptr got, unsigned long u, mpf_srcptr v) +{ + mpf_t uf; + mp_limb_t ulimbs[2]; + mp_size_t usize; + + ulimbs[0] = u & GMP_NUMB_MASK; + usize = (u != 0); +#if BITS_PER_ULONG > GMP_NUMB_BITS + u >>= GMP_NUMB_BITS; + ulimbs[1] = u; + usize += (u != 0); +#endif + PTR(uf) = ulimbs; + SIZ(uf) = usize; + EXP(uf) = usize; + + if (! refmpf_validate_division ("mpf_ui_div", got, uf, v)) + { + mp_trace_base = -16; + printf (" u 0x%lX (%lu)\n", u, u); + mpf_trace (" v", v); + printf (" %s\n", desc); + abort (); + } +} + +void +check_rand (void) +{ + unsigned long min_prec = __GMPF_BITS_TO_PREC (1); + gmp_randstate_ptr rands = RANDS; + unsigned long prec, u; + mpf_t got, v; + int i; + + mpf_init (got); + mpf_init (v); + + for (i = 0; i < 200; i++) + { + /* got precision */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (got, prec); + + /* u */ + prec = gmp_urandomm_ui (rands, BITS_PER_ULONG+1); + u = gmp_urandomb_ui (rands, prec); + + /* v precision */ + prec = min_prec + gmp_urandomm_ui (rands, 15L); + refmpf_set_prec_limbs (v, prec); + + /* v, non-zero */ + do { + mpf_random2 (v, PREC(v), (mp_exp_t) 20); + } while (SIZ(v) == 0); + + /* v possibly negative */ + if (gmp_urandomb_ui (rands, 1L)) + mpf_neg (v, v); + + if ((i % 2) == 0) + { + /* src != dst */ + mpf_ui_div (got, u, v); + check_one ("separate", got, u, v); + } + else + { + /* src == dst */ + prec = refmpf_set_overlap (got, v); + mpf_ui_div (got, u, got); + check_one ("overlap src==dst", got, u, v); + + mpf_set_prec_raw (got, prec); + } + } + + mpf_clear (got); + mpf_clear (v); +} + +void +check_various (void) +{ + mpf_t got, v; + + mpf_init (got); + mpf_init (v); + + /* 100/4 == 25 */ + mpf_set_prec (got, 20L); + mpf_set_ui (v, 4L); + mpf_ui_div (got, 100L, v); + MPF_CHECK_FORMAT (got); + ASSERT_ALWAYS (mpf_cmp_ui (got, 25L) == 0); + + { + /* 1/(2^n+1), a case where truncating the divisor would be wrong */ + unsigned long u = 1L; + mpf_set_prec (got, 500L); + mpf_set_prec (v, 900L); + mpf_set_ui (v, 1L); + mpf_mul_2exp (v, v, 800L); + mpf_add_ui (v, v, 1L); + mpf_ui_div (got, u, v); + check_one ("1/2^n+1, separate", got, u, v); + } + + mpf_clear (got); + mpf_clear (v); +} + +int +main (void) +{ + tests_start (); + + check_various (); + check_rand (); + + tests_end (); + exit (0); +} |