diff options
author | Kevin Ryde <user42@zip.com.au> | 2000-09-10 01:10:14 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2000-09-10 01:10:14 +0200 |
commit | 8bd0cf098ea07cba905889c62edd9d204c4b5c50 (patch) | |
tree | 7b9b80aefe0156ed48f877f12eb777f8034381fd /mpq/abs.c | |
parent | 9bc2d1044854454f9ba6921008d9cc1bd6412938 (diff) | |
download | gmp-8bd0cf098ea07cba905889c62edd9d204c4b5c50.tar.gz |
* mpq/abs.c: New file.
Diffstat (limited to 'mpq/abs.c')
-rw-r--r-- | mpq/abs.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mpq/abs.c b/mpq/abs.c new file mode 100644 index 000000000..5d9de7026 --- /dev/null +++ b/mpq/abs.c @@ -0,0 +1,46 @@ +/* mpq_abs -- absolute value of a rational. + +Copyright (C) 2000 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP 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 2.1 of the License, or (at your +option) any later version. + +The GNU MP 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 MP Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ + +#include "gmp.h" +#include "gmp-impl.h" + + +void +mpq_abs (mpq_ptr dst, mpq_srcptr src) +{ + mp_size_t num_size = src->_mp_num._mp_size; + mp_size_t num_abs_size = ABS (num_size); + + if (dst != src) + { + mp_size_t den_size = src->_mp_den._mp_size; + + MPZ_REALLOC (mpq_numref(dst), num_abs_size); + MPZ_REALLOC (mpq_denref(dst), den_size); + + MPN_COPY (dst->_mp_num._mp_d, src->_mp_num._mp_d, num_abs_size); + MPN_COPY (dst->_mp_den._mp_d, src->_mp_den._mp_d, den_size); + + dst->_mp_den._mp_size = den_size; + } + + dst->_mp_num._mp_size = num_abs_size; +} |