From c9583bdfe064e1069828e518533f7bc29a8fdddb Mon Sep 17 00:00:00 2001 From: vlefevre Date: Tue, 17 Aug 2010 09:10:13 +0000 Subject: Source reorganization. In short: * Added directories and moved related files into them: - src for the MPFR source files (to build the library). - doc for documentation files (except INSTALL, README...). - tools for various tools (scripts) and mbench. - tune for tuneup-related source files. - other for other source files (not distributed in tarballs). Existing directories: - tests for the source files of the test suite (make check). - examples for examples. - m4 for m4 files. * Renamed configure.in to configure.ac. * Added/updated Makefile.am files where needed. * Updated acinclude.m4 and configure.ac (AC_CONFIG_FILES line). * Updated the documentation (INSTALL, README, doc/README.dev and doc/mpfr.texi). * Updated NEWS and TODO. * Updated the scripts now in tools. The following script was used: #!/usr/bin/env zsh svn mkdir doc other src tools tune svn mv ${${(M)$(sed -n '/libmpfr_la_SOURCES/,/[^\]$/p' \ Makefile.am):#*.[ch]}:#get_patches.c} mparam_h.in \ round_raw_generic.c jyn_asympt.c src svn mv mbench check_inits_clears coverage get_patches.sh mpfrlint \ nightly-test update-patchv update-version tools svn mv bidimensional_sample.c speed.c tuneup.c tune svn mv *.{c,h} other svn mv FAQ.html README.dev algorithm* faq.xsl fdl.texi mpfr.texi \ update-faq doc svn mv configure.in configure.ac svn cp Makefile.am src/Makefile.am svn rm replace_all [Modifying some files, see above] svn add doc/Makefile.am svn add tune/Makefile.am git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7087 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/modf.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/modf.c (limited to 'src/modf.c') diff --git a/src/modf.c b/src/modf.c new file mode 100644 index 000000000..4e9a0b4ad --- /dev/null +++ b/src/modf.c @@ -0,0 +1,98 @@ +/* mpfr_modf -- Integral and fractional part. + +Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +Contributed by the Arenaire and Caramel projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser 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 MPFR Library 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 Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "mpfr-impl.h" + +#define INEXPOS(y) ((y) == 0 ? 0 : (((y) > 0) ? 1 : 2)) +#define INEX(y,z) (INEXPOS(y) | (INEXPOS(z) << 2)) + +/* Set iop to the integral part of op and fop to its fractional part */ +int +mpfr_modf (mpfr_ptr iop, mpfr_ptr fop, mpfr_srcptr op, mpfr_rnd_t rnd_mode) +{ + mpfr_exp_t ope; + mpfr_prec_t opq; + int inexi, inexf; + + MPFR_LOG_FUNC (("op[%#R]=%R rnd=%d", op, op, rnd_mode), + ("iop[%#R]=%R fop[%#R]=%R", iop, iop, fop, fop)); + + MPFR_ASSERTN (iop != fop); + + if ( MPFR_UNLIKELY (MPFR_IS_SINGULAR (op)) ) + { + if (MPFR_IS_NAN (op)) + { + MPFR_SET_NAN (iop); + MPFR_SET_NAN (fop); + MPFR_RET_NAN; + } + MPFR_SET_SAME_SIGN (iop, op); + MPFR_SET_SAME_SIGN (fop, op); + if (MPFR_IS_INF (op)) + { + MPFR_SET_INF (iop); + MPFR_SET_ZERO (fop); + MPFR_RET (0); + } + else /* op is zero */ + { + MPFR_ASSERTD (MPFR_IS_ZERO (op)); + MPFR_SET_ZERO (iop); + MPFR_SET_ZERO (fop); + MPFR_RET (0); + } + } + + ope = MPFR_GET_EXP (op); + opq = MPFR_PREC (op); + + if (ope <= 0) /* 0 < |op| < 1 */ + { + inexf = (fop != op) ? mpfr_set (fop, op, rnd_mode) : 0; + MPFR_SET_SAME_SIGN (iop, op); + MPFR_SET_ZERO (iop); + MPFR_RET (INEX(0, inexf)); + } + else if (ope >= opq) /* op has no fractional part */ + { + inexi = (iop != op) ? mpfr_set (iop, op, rnd_mode) : 0; + MPFR_SET_SAME_SIGN (fop, op); + MPFR_SET_ZERO (fop); + MPFR_RET (INEX(inexi, 0)); + } + else /* op has both integral and fractional parts */ + { + if (iop != op) + { + inexi = mpfr_rint_trunc (iop, op, rnd_mode); + inexf = mpfr_frac (fop, op, rnd_mode); + } + else + { + MPFR_ASSERTN (fop != op); + inexf = mpfr_frac (fop, op, rnd_mode); + inexi = mpfr_rint_trunc (iop, op, rnd_mode); + } + MPFR_RET (INEX(inexi, inexf)); + } +} -- cgit v1.2.1