]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
float128: Add conversion from float128 to mpn
authorGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Thu, 3 Nov 2016 14:26:52 +0000 (12:26 -0200)
committerGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Thu, 25 May 2017 12:20:39 +0000 (09:20 -0300)
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.

include/gmp.h
misc/sys/param.h
sysdeps/ieee754/float128/Makefile [new file with mode: 0644]
sysdeps/ieee754/float128/float1282mpn.c [new file with mode: 0644]
sysdeps/ieee754/ldbl-128/ldbl2mpn.c

index b74167097d91549fc01b478fdcdaae08c3036c71..95d6c16f14695e2f63e9ef80fce93f2e47b4e9b1 100644 (file)
@@ -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,
index 97216135f29beea91ec5a155d60a3ea789b843b6..02d6b1c533ad890dea3042a078b9f6f120fc663e 100644 (file)
 #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 (file)
index 0000000..6a7b0e0
--- /dev/null
@@ -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 (file)
index 0000000..b0dd2e9
--- /dev/null
@@ -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"
index 71a6f043bd236e10a0e1711b14dbc13644160915..e23cb76b1bea110df22d833fdf2ffd1dfcfdaa8a 100644 (file)
 #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
    (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;