diff options
Diffstat (limited to 'sysdeps/ieee754/float128')
-rw-r--r-- | sysdeps/ieee754/float128/Makefile | 5 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/Versions | 10 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/mpn2float128.c | 54 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/strtod_nan_float128.h | 33 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/strtof128.c | 34 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/strtof128_l.c | 43 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/strtof128_nan.c | 28 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/wcstof128.c | 30 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/wcstof128_l.c | 30 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/wcstof128_nan.c | 24 |
10 files changed, 291 insertions, 0 deletions
diff --git a/sysdeps/ieee754/float128/Makefile b/sysdeps/ieee754/float128/Makefile index c07586c1b6..166e630290 100644 --- a/sysdeps/ieee754/float128/Makefile +++ b/sysdeps/ieee754/float128/Makefile @@ -1,3 +1,8 @@ ifeq ($(subdir),stdlib) routines += float1282mpn strfromf128 +routines += strtof128 strtof128_l strtof128_nan mpn2float128 +endif + +ifeq ($(subdir),wcsmbs) +routines += wcstof128_l wcstof128 wcstof128_nan endif diff --git a/sysdeps/ieee754/float128/Versions b/sysdeps/ieee754/float128/Versions index caf206475c..ef9df2d4c8 100644 --- a/sysdeps/ieee754/float128/Versions +++ b/sysdeps/ieee754/float128/Versions @@ -4,7 +4,17 @@ %endif libc { FLOAT128_VERSION { + __strtof128_internal; + __wcstof128_internal; strfromf128; + strtof128; + strtof128_l; + wcstof128; + wcstof128_l; + } + GLIBC_PRIVATE { + # For __nanf128. + __strtof128_nan; } } libm { diff --git a/sysdeps/ieee754/float128/mpn2float128.c b/sysdeps/ieee754/float128/mpn2float128.c new file mode 100644 index 0000000000..12f703a757 --- /dev/null +++ b/sysdeps/ieee754/float128/mpn2float128.c @@ -0,0 +1,54 @@ +/* Convert a number in multi-precision format to _Float128. + 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/>. */ + +#include "gmp.h" +#include "gmp-impl.h" +#include <float.h> +#include <math.h> + +#include "ieee754_float128.h" + +/* Convert a multi-precision integer of the needed number of bits (113 for + binary128) and an integral power of two to a `_Float128' in IEEE854 + quad-precision format. */ + +_Float128 +__mpn_construct_float128 (mp_srcptr frac_ptr, int expt, int sign) +{ + union ieee854_float128 u; + + u.ieee.negative = sign; + u.ieee.exponent = expt + IEEE854_FLOAT128_BIAS; +#if BITS_PER_MP_LIMB == 32 + u.ieee.mantissa3 = frac_ptr[0]; + u.ieee.mantissa2 = frac_ptr[1]; + u.ieee.mantissa1 = frac_ptr[2]; + u.ieee.mantissa0 = frac_ptr[3] & (((mp_limb_t) 1 + << (FLT128_MANT_DIG - 96)) - 1); +#elif BITS_PER_MP_LIMB == 64 + u.ieee.mantissa3 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1); + u.ieee.mantissa2 = frac_ptr[0] >> 32; + u.ieee.mantissa1 = frac_ptr[1] & (((mp_limb_t) 1 << 32) - 1); + u.ieee.mantissa0 = (frac_ptr[1] >> 32) & (((mp_limb_t) 1 + << (FLT128_MANT_DIG - 96)) - 1); +#else + #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for" +#endif + + return u.d; +} diff --git a/sysdeps/ieee754/float128/strtod_nan_float128.h b/sysdeps/ieee754/float128/strtod_nan_float128.h new file mode 100644 index 0000000000..79329fb1f6 --- /dev/null +++ b/sysdeps/ieee754/float128/strtod_nan_float128.h @@ -0,0 +1,33 @@ +/* Convert string for NaN payload to corresponding NaN. For _Float128. + 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 FLOAT _Float128 +#define SET_MANTISSA(flt, mant) \ + do \ + { \ + union ieee854_float128 u; \ + u.d = (flt); \ + u.ieee_nan.mantissa0 = 0; \ + u.ieee_nan.mantissa1 = 0; \ + u.ieee_nan.mantissa2 = (mant) >> 32; \ + u.ieee_nan.mantissa3 = (mant); \ + if ((u.ieee.mantissa0 | u.ieee.mantissa1 \ + | u.ieee.mantissa2 | u.ieee.mantissa3) != 0) \ + (flt) = u.d; \ + } \ + while (0) diff --git a/sysdeps/ieee754/float128/strtof128.c b/sysdeps/ieee754/float128/strtof128.c new file mode 100644 index 0000000000..63cc80d58d --- /dev/null +++ b/sysdeps/ieee754/float128/strtof128.c @@ -0,0 +1,34 @@ +/* strtof128 wrapper of strtof128_l. + 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/>. */ + +/* The actual implementation for all floating point sizes is in strtod.c. + These macros tell it to produce the `_Float128' version, `strtof128'. */ + +#define FLOAT _Float128 +#define FLT FLT128 +#ifdef USE_WIDE_CHAR +# define STRTOF wcstof128 +# define STRTOF_L __wcstof128_l +#else +# define STRTOF strtof128 +# define STRTOF_L __strtof128_l +#endif + +#include <float128_private.h> + +#include <stdlib/strtod.c> diff --git a/sysdeps/ieee754/float128/strtof128_l.c b/sysdeps/ieee754/float128/strtof128_l.c new file mode 100644 index 0000000000..0f768a30de --- /dev/null +++ b/sysdeps/ieee754/float128/strtof128_l.c @@ -0,0 +1,43 @@ +/* Convert string representing a number to a _Float128 value, with locale. + 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/>. */ + +#include <xlocale.h> + +/* Bring in potential typedef for _Float128 early for declaration below. */ +#include <bits/floatn.h> + +extern _Float128 ____strtof128_l_internal (const char *, char **, + int, __locale_t); + +#define FLOAT _Float128 +#define FLT FLT128 +#ifdef USE_WIDE_CHAR +# define STRTOF wcstof128_l +# define __STRTOF __wcstof128_l +# define STRTOF_NAN __wcstof128_nan +#else +# define STRTOF strtof128_l +# define __STRTOF __strtof128_l +# define STRTOF_NAN __strtof128_nan +#endif +#define MPN2FLOAT __mpn_construct_float128 +#define FLOAT_HUGE_VAL __builtin_huge_valf128 () + +#include <float128_private.h> + +#include <stdlib/strtod_l.c> diff --git a/sysdeps/ieee754/float128/strtof128_nan.c b/sysdeps/ieee754/float128/strtof128_nan.c new file mode 100644 index 0000000000..b9d79e3089 --- /dev/null +++ b/sysdeps/ieee754/float128/strtof128_nan.c @@ -0,0 +1,28 @@ +/* Convert string for NaN payload to corresponding NaN. Narrow + strings, __float128. + 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/>. */ + +#include <math.h> + +#include <float128_private.h> + +#include <strtod_nan_narrow.h> +#include <strtod_nan_float128.h> + +#define STRTOD_NAN __strtof128_nan +#include <stdlib/strtod_nan_main.c> diff --git a/sysdeps/ieee754/float128/wcstof128.c b/sysdeps/ieee754/float128/wcstof128.c new file mode 100644 index 0000000000..c5a17baadf --- /dev/null +++ b/sysdeps/ieee754/float128/wcstof128.c @@ -0,0 +1,30 @@ +/* wcstof128 wrapper of wcstof128_l. + 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/>. */ + +#include <stddef.h> +#include <xlocale.h> + +#define USE_WIDE_CHAR 1 + +/* Bring in _Float128 typedef if needed. */ +#include <bits/floatn.h> + +extern _Float128 ____wcstof128_l_internal (const wchar_t *, wchar_t **, int, + __locale_t); + +#include "strtof128.c" diff --git a/sysdeps/ieee754/float128/wcstof128_l.c b/sysdeps/ieee754/float128/wcstof128_l.c new file mode 100644 index 0000000000..670b6af0da --- /dev/null +++ b/sysdeps/ieee754/float128/wcstof128_l.c @@ -0,0 +1,30 @@ +/* Convert string representing a number to integer value, using given locale. + 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/>. */ + +#include <stddef.h> +#include <xlocale.h> + + +#define USE_WIDE_CHAR 1 + +#include <bits/floatn.h> + +extern _Float128 ____wcstof128_l_internal (const wchar_t *, wchar_t **, int, + __locale_t); + +#include "strtof128_l.c" diff --git a/sysdeps/ieee754/float128/wcstof128_nan.c b/sysdeps/ieee754/float128/wcstof128_nan.c new file mode 100644 index 0000000000..abad881ef5 --- /dev/null +++ b/sysdeps/ieee754/float128/wcstof128_nan.c @@ -0,0 +1,24 @@ +/* Convert string for NaN payload to corresponding NaN. Wide strings, + _Float128. + 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/>. */ + +#include <stdlib/strtod_nan_wide.h> +#include <float128_private.h> +#include <strtod_nan_float128.h> +#define STRTOD_NAN __wcstof128_nan +#include <stdlib/strtod_nan_main.c> |