diff options
author | Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com> | 2016-11-03 12:26:52 -0200 |
---|---|---|
committer | Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com> | 2017-05-25 09:20:39 -0300 |
commit | fb91e22c252dbefd1b141fdf151903cf5aea7727 (patch) | |
tree | aa3dd64e3ec3930cc275d2b1be86b5e63d04f337 | |
parent | ec9052ea0cb8baceee57ab26ca526b30f365dff9 (diff) | |
download | glibc-fb91e22c252dbefd1b141fdf151903cf5aea7727.tar.gz glibc-fb91e22c252dbefd1b141fdf151903cf5aea7727.tar.xz glibc-fb91e22c252dbefd1b141fdf151903cf5aea7727.zip |
float128: Add conversion from float128 to mpn
Reuse the code for __mpn_extract_long_double to implement __mpn_extract_float128. 2017-05-15 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com> * include/gmp.h (__mpn_extract_float128): Declare when __HAVE_DISTINCT_FLOAT128 is 1. * misc/sys/param.h (MIN, MAX): Only define if not yet defined. * sysdeps/ieee754/float128/Makefile: New file. * sysdeps/ieee754/float128/float1282mpn.c: New file. * sysdeps/ieee754/ldbl-128/ldbl2mpn.c (__mpn_extract_float128): New function, which is built when __FLOAT128_OVERRIDE is defined.
-rw-r--r-- | include/gmp.h | 6 | ||||
-rw-r--r-- | misc/sys/param.h | 8 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/Makefile | 3 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/float1282mpn.c | 20 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128/ldbl2mpn.c | 18 |
5 files changed, 49 insertions, 6 deletions
diff --git a/include/gmp.h b/include/gmp.h index b74167097d..95d6c16f14 100644 --- a/include/gmp.h +++ b/include/gmp.h @@ -15,6 +15,12 @@ extern mp_size_t __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size, int *expt, int *is_neg, long double value); +#if __HAVE_DISTINCT_FLOAT128 +extern mp_size_t __mpn_extract_float128 (mp_ptr res_ptr, mp_size_t size, + int *expt, int *is_neg, + _Float128 value); +#endif + extern float __mpn_construct_float (mp_srcptr frac_ptr, int expt, int sign); extern double __mpn_construct_double (mp_srcptr frac_ptr, int expt, diff --git a/misc/sys/param.h b/misc/sys/param.h index 97216135f2..02d6b1c533 100644 --- a/misc/sys/param.h +++ b/misc/sys/param.h @@ -99,8 +99,12 @@ #define powerof2(x) ((((x) - 1) & (x)) == 0) /* Macros for min/max. */ -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef MAX +# define MAX(a,b) (((a)>(b))?(a):(b)) +#endif #endif /* sys/param.h */ diff --git a/sysdeps/ieee754/float128/Makefile b/sysdeps/ieee754/float128/Makefile new file mode 100644 index 0000000000..6a7b0e0f45 --- /dev/null +++ b/sysdeps/ieee754/float128/Makefile @@ -0,0 +1,3 @@ +ifeq ($(subdir),stdlib) +routines += float1282mpn +endif diff --git a/sysdeps/ieee754/float128/float1282mpn.c b/sysdeps/ieee754/float128/float1282mpn.c new file mode 100644 index 0000000000..b0dd2e9844 --- /dev/null +++ b/sysdeps/ieee754/float128/float1282mpn.c @@ -0,0 +1,20 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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 C 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 C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define __FLOAT128_OVERRIDE + +#include "../ldbl-128/ldbl2mpn.c" diff --git a/sysdeps/ieee754/ldbl-128/ldbl2mpn.c b/sysdeps/ieee754/ldbl-128/ldbl2mpn.c index 71a6f043bd..e23cb76b1b 100644 --- a/sysdeps/ieee754/ldbl-128/ldbl2mpn.c +++ b/sysdeps/ieee754/ldbl-128/ldbl2mpn.c @@ -18,10 +18,14 @@ #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" -#include <ieee754.h> -#include <float.h> -#include <math.h> -#include <stdlib.h> + +#ifdef __FLOAT128_OVERRIDE +# include <float128_private.h> +#else +# include <ieee754.h> +# include <float.h> +# include <math.h> +#endif /* Convert a `long double' in IEEE854 quad-precision format to a multi-precision integer representing the significand scaled up by its @@ -29,9 +33,15 @@ (MPN frexpl). */ mp_size_t +#ifdef __FLOAT128_OVERRIDE +__mpn_extract_float128 (mp_ptr res_ptr, mp_size_t size, + int *expt, int *is_neg, + _Float128 value) +#else __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size, int *expt, int *is_neg, long double value) +#endif { union ieee854_long_double u; u.d = value; |