From patchwork Fri Jun 9 16:53:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 774073 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkpL62t6rz9s9Y for ; Sat, 10 Jun 2017 02:54:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Plf0ORTx"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:in-reply-to:references :message-id; q=dns; s=default; b=bMyO+pJ8XIl8eTFzGl2xKNyEBC95eLq v8pnxTZf2CrpM0wkeSGjNOTHYHQWFcshqUbX5yYau9lGXux7VEPObnWV3U6ZjqMY qclbIutvBGJJAEHvUkVpigeRZqTt5/tAeREICtVPfecjTaRlV76gvPqtKqaWaWPO MyvmU2Mp9TzM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:in-reply-to:references :message-id; s=default; bh=5Qi5SguMer52RJfoojHtTadVHAI=; b=Plf0O RTxv+4NIvGeujBE9msvy2ftQfi4Jkk0MsNuziUJfTyl/WfS+eE3qaWC+sYWsvhSu HyXAYjHW+BnNerdPOgjum2VvANMxf0PLlNb0wzF5N73cGaX+j3o8lLuKsEUYxqWn 3Diw4n3xSgGE8US/1ZMPnlixBQjJC/Gj5s4Tuk= Received: (qmail 34835 invoked by alias); 9 Jun 2017 16:54:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 33990 invoked by uid 89); 9 Jun 2017 16:54:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com From: "Gabriel F. T. Gomes" To: libc-alpha@sourceware.org Subject: [PATCH v4 1/2] float128: Add strtof128, wcstof128, and related functions. Date: Fri, 9 Jun 2017 13:53:55 -0300 In-Reply-To: <1497027236-22078-1-git-send-email-gftg@linux.vnet.ibm.com> References: <1497027236-22078-1-git-send-email-gftg@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17060916-0032-0000-0000-00000568AE48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17060916-0033-0000-0000-000011EEC6C1 Message-Id: <1497027236-22078-2-git-send-email-gftg@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-09_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706090294 From: "Paul E. Murphy" Changes since v3: - Removed the definition of CHAR (defined before inclusion). - Converted the unnecessarily complex macros (_GEN and _DO) into IF_FLOAT128. Changes since v2: - Fixed the condition for defining F128 (no dependency on compiler version). - Fixed the condition for defining CHAR (no dependency on __HAVE_FLOAT128). - Removed the unnecessary indirections in the macros _GEN and _DO. - Fixed the condition for declaring wcstof128 (__USE_GNU, not TS 18661-3). Changes since v1: - Removed NEWS entry to the commit that actually enables strtof128. - Removed the check for __STDC_WANT_IEC_60559_TYPES_EXT__ from blocks of code that are inside __USE_GNU conditional. - Moved the declaration of wcstof128 closer to wcstod, wcstof, and wcstold. - Redefined F128 in the tests to use the existing workaround for old. compilers (i.e.: __f128 ()). - Added descriptive comment before the copyright, as needed. -- 8< -- The implementations are contained with sysdeps/ieee754/float128 as they are only built when _Float128 is enabled within libc/m. 2017-05-23 Paul E. Murphy * include/gmp.h (__mpn_construct_float128): New declaration. * include/stdlib.h: Include bits/floatn.h for _Float128 tests. (__strtof128_l): New declaration. (__strtof128_nan): Likewise. (__wcstof128_nan): Likewise. (__strtof128_internal): Likewise. (____strtof128_l_internal): Likewise. * include/wchar.h: Include bits/floatn.h for _Float128 tests. (__wcstof128_l): New declaration. (__wcstof128_internal): Likewise. * stdlib/Makefile (bug-strtod2): Link libm too. * stdlib/stdlib.h (strtof128): New declaration. (strtof128_l): Likewise. * stdlib/tst-strtod-nan-locale-main.c: Updated to use tst-strtod.h macros to ensure float128 gets tested too. * stdlib/tst-strtod-round-skeleton.c (CHOOSE_f128): New macro. * stdlib/tst-strtod.h: Include bits/floatn.h for _Float128 tests. (IF_FLOAT128): New macro. (GEN_TEST_STRTOD): Update to optionally include _Float128 in the tests. (STRTOD_TEST_FOREACH): Likewise. * sysdeps/ieee754/float128/Makefile: Insert new strtof128 and wcstof128 functions into libc. * sysdeps/ieee754/float128/Versions: Add exports for the above new functions. * sysdeps/ieee754/float128/mpn2float128.c: New file. * sysdeps/ieee754/float128/strtod_nan_float128.h: New file. * sysdeps/ieee754/float128/strtof128.c: New file. * sysdeps/ieee754/float128/strtof128_l.c: New file. * sysdeps/ieee754/float128/strtof128_nan.c: New file. * sysdeps/ieee754/float128/wcstof128.c: New file. * sysdeps/ieee754/float128/wcstof128_l.c: New file. * sysdeps/ieee754/float128/wcstof128_nan.c: New fike. * wcsmbs/Makefile: (CFLAGS-wcstof128.c): Append strtox-CFLAGS. (CFLAGS-wcstof128_l): Likewise. * wcsmbs/wchar.h: Include bits/floatn.h for _Float128 tests. (wcstof128): New declaration. (wcstof128_l): Likewise. --- include/gmp.h | 4 ++ include/stdlib.h | 29 ++++++++++++++ include/wchar.h | 13 +++++++ stdlib/Makefile | 1 + stdlib/stdlib.h | 14 +++++++ stdlib/tst-strtod-nan-locale-main.c | 36 ++++++++--------- stdlib/tst-strtod-round-skeleton.c | 1 + stdlib/tst-strtod.h | 36 +++++++++++------ sysdeps/ieee754/float128/Makefile | 5 +++ sysdeps/ieee754/float128/Versions | 10 +++++ sysdeps/ieee754/float128/mpn2float128.c | 54 ++++++++++++++++++++++++++ sysdeps/ieee754/float128/strtod_nan_float128.h | 33 ++++++++++++++++ sysdeps/ieee754/float128/strtof128.c | 34 ++++++++++++++++ sysdeps/ieee754/float128/strtof128_l.c | 43 ++++++++++++++++++++ sysdeps/ieee754/float128/strtof128_nan.c | 28 +++++++++++++ sysdeps/ieee754/float128/wcstof128.c | 30 ++++++++++++++ sysdeps/ieee754/float128/wcstof128_l.c | 30 ++++++++++++++ sysdeps/ieee754/float128/wcstof128_nan.c | 24 ++++++++++++ wcsmbs/Makefile | 2 + wcsmbs/wchar.h | 15 +++++++ 20 files changed, 413 insertions(+), 29 deletions(-) create mode 100644 sysdeps/ieee754/float128/mpn2float128.c create mode 100644 sysdeps/ieee754/float128/strtod_nan_float128.h create mode 100644 sysdeps/ieee754/float128/strtof128.c create mode 100644 sysdeps/ieee754/float128/strtof128_l.c create mode 100644 sysdeps/ieee754/float128/strtof128_nan.c create mode 100644 sysdeps/ieee754/float128/wcstof128.c create mode 100644 sysdeps/ieee754/float128/wcstof128_l.c create mode 100644 sysdeps/ieee754/float128/wcstof128_nan.c diff --git a/include/gmp.h b/include/gmp.h index e6f635e..3590acf 100644 --- a/include/gmp.h +++ b/include/gmp.h @@ -31,5 +31,9 @@ extern double __mpn_construct_double (mp_srcptr frac_ptr, int expt, extern long double __mpn_construct_long_double (mp_srcptr frac_ptr, int expt, int sign); +#if __HAVE_DISTINCT_FLOAT128 +extern _Float128 __mpn_construct_float128 (mp_srcptr frac_ptr, int expt, + int sign); +#endif #endif diff --git a/include/stdlib.h b/include/stdlib.h index 5847445..cae9f2c 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -219,6 +219,35 @@ libc_hidden_proto (__wcstof_nan) libc_hidden_proto (__wcstod_nan) libc_hidden_proto (__wcstold_nan) +/* Enable _FloatN bits as needed. */ +#include + +#if __HAVE_DISTINCT_FLOAT128 +extern __typeof (strtof128_l) __strtof128_l; + +libc_hidden_proto (__strtof128_l) +libc_hidden_proto (strtof128) + +extern _Float128 __strtof128_nan (const char *, char **, char) + internal_function; +extern _Float128 __wcstof128_nan (const wchar_t *, wchar_t **, wchar_t) + internal_function; + +libc_hidden_proto (__strtof128_nan) +libc_hidden_proto (__wcstof128_nan) + +extern _Float128 __strtof128_internal (const char *__restrict __nptr, + char **__restrict __endptr, + int __group); +libc_hidden_proto (__strtof128_internal) + +extern _Float128 ____strtof128_l_internal (const char *__restrict __nptr, + char **__restrict __endptr, + int __group, __locale_t __loc); + +libc_hidden_proto (____strtof128_l_internal) +#endif + extern char *__ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign); extern char *__fcvt (double __value, int __ndigit, int *__restrict __decpt, diff --git a/include/wchar.h b/include/wchar.h index a773d56..55de9be 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -4,6 +4,8 @@ # ifndef _ISOMAC # ifdef _WCHAR_H +#include + extern __typeof (wcscasecmp_l) __wcscasecmp_l; extern __typeof (wcsncasecmp_l) __wcsncasecmp_l; extern __typeof (wcscoll_l) __wcscoll_l; @@ -70,6 +72,17 @@ libc_hidden_proto (wcstoll) libc_hidden_proto (wcstoul) libc_hidden_proto (wcstoull) +#if __HAVE_DISTINCT_FLOAT128 +extern __typeof (wcstof128_l) __wcstof128_l; +libc_hidden_proto (__wcstof128_l) +extern _Float128 __wcstof128_internal (const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + int __group) __THROW; + +libc_hidden_proto (__wcstof128_internal) +libc_hidden_proto (wcstof128) +#endif + libc_hidden_proto (__wcscasecmp_l) libc_hidden_proto (__wcsncasecmp_l) diff --git a/stdlib/Makefile b/stdlib/Makefile index 9b0acce..0314d59 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -198,6 +198,7 @@ $(objpfx)tst-putenvmod.so: $(objpfx)tst-putenvmod.os $(link-libc-deps) libof-tst-putenvmod = extramodules $(objpfx)bug-getcontext: $(libm) +$(objpfx)bug-strtod2: $(libm) $(objpfx)tst-strtod-round: $(libm) $(objpfx)tst-tininess: $(libm) $(objpfx)tst-strtod-underflow: $(libm) diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index 0a693c2..6f1e70e 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -128,6 +128,13 @@ extern long double strtold (const char *__restrict __nptr, __THROW __nonnull ((1)); #endif +#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) +/* Likewise for the '_Float128' format */ +extern _Float128 strtof128 (const char *__restrict __nptr, + char **__restrict __endptr) + __THROW __nonnull ((1)); +#endif + /* Convert a string to a long integer. */ extern long int strtol (const char *__restrict __nptr, char **__restrict __endptr, int __base) @@ -236,6 +243,13 @@ extern long double strtold_l (const char *__restrict __nptr, char **__restrict __endptr, __locale_t __loc) __THROW __nonnull ((1, 3)); + +# if __HAVE_FLOAT128 +extern _Float128 strtof128_l (const char *__restrict __nptr, + char **__restrict __endptr, + __locale_t __loc) + __THROW __nonnull ((1, 3)); +# endif #endif /* GNU */ diff --git a/stdlib/tst-strtod-nan-locale-main.c b/stdlib/tst-strtod-nan-locale-main.c index 8044dad..8222174 100644 --- a/stdlib/tst-strtod-nan-locale-main.c +++ b/stdlib/tst-strtod-nan-locale-main.c @@ -23,6 +23,8 @@ #include #include +#include + #define STR_(X) #X #define STR(X) STR_(X) #define FNPFXS STR (FNPFX) @@ -30,20 +32,22 @@ #define CONCAT(X, Y) CONCAT_ (X, Y) #define FNX(FN) CONCAT (FNPFX, FN) -#define TEST(LOC, STR, FN, TYPE) \ - do \ +#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \ +static int \ +test_strto ## FSUF (const char * loc, CHAR * s) \ +{ \ + CHAR *ep; \ + FTYPE val = FNX (FSUF) (s, &ep); \ + if (isnan (val) && *ep == 0) \ + printf ("PASS: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s); \ + else \ { \ - CHAR *ep; \ - TYPE val = FNX (FN) (STR, &ep); \ - if (isnan (val) && *ep == 0) \ - printf ("PASS: %s: " FNPFXS #FN " (" SFMT ")\n", LOC, STR); \ - else \ - { \ - printf ("FAIL: %s: " FNPFXS #FN " (" SFMT ")\n", LOC, STR); \ - result = 1; \ - } \ + printf ("FAIL: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s); \ + return 1; \ } \ - while (0) + return 0; \ +} +GEN_TEST_STRTOD_FOREACH (TEST_STRTOD) static int test_one_locale (const char *loc) @@ -64,13 +68,9 @@ test_one_locale (const char *loc) s[4] = L_('A') + i - 10; s[5] = L_(')'); s[6] = 0; - TEST (loc, s, f, float); - TEST (loc, s, d, double); - TEST (loc, s, ld, long double); + result |= STRTOD_TEST_FOREACH (test_strto, loc, s); s[4] = L_('a') + i - 10; - TEST (loc, s, f, float); - TEST (loc, s, d, double); - TEST (loc, s, ld, long double); + result |= STRTOD_TEST_FOREACH (test_strto, loc, s); } return result; } diff --git a/stdlib/tst-strtod-round-skeleton.c b/stdlib/tst-strtod-round-skeleton.c index 73603e6..1a9f663 100644 --- a/stdlib/tst-strtod-round-skeleton.c +++ b/stdlib/tst-strtod-round-skeleton.c @@ -93,6 +93,7 @@ /* Add type specific choosing macros below. */ #define CHOOSE_f(f,...) f #define CHOOSE_d(f,d,...) d +#define CHOOSE_f128(f,d,ld64i,ld64m,ld106,ld113,...) ld113 /* long double is special, and handled above. */ /* Selector for expected result field of a given type. */ diff --git a/stdlib/tst-strtod.h b/stdlib/tst-strtod.h index bf5f901..e23ac3f 100644 --- a/stdlib/tst-strtod.h +++ b/stdlib/tst-strtod.h @@ -21,11 +21,24 @@ #define FSTRLENMAX 128 +#include + +#define F128 __f128 () + +/* Test strfromf128 and strtof128 on all platforms that provide them, + whether or not the type _Float128 is ABI-distinct from long double. */ +#if __HAVE_FLOAT128 +# define IF_FLOAT128(x) x +#else +# define IF_FLOAT128(x) +#endif + /* Splat n variants of the same test for the various strtod functions. */ -#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \ - mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \ - mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \ - mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__) +#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \ + mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \ + mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \ + mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__) \ + IF_FLOAT128 (mfunc (f128, _Float128, strfromf128, F128, f128, ##__VA_ARGS__)) /* The arguments to the generated macros are: FSUF - Function suffix FTYPE - float type @@ -36,13 +49,14 @@ -#define STRTOD_TEST_FOREACH(mfunc, ...) \ -({ \ - int result = 0; \ - result |= mfunc ## f (__VA_ARGS__); \ - result |= mfunc ## d (__VA_ARGS__); \ - result |= mfunc ## ld (__VA_ARGS__); \ - result; \ +#define STRTOD_TEST_FOREACH(mfunc, ...) \ +({ \ + int result = 0; \ + result |= mfunc ## f (__VA_ARGS__); \ + result |= mfunc ## d (__VA_ARGS__); \ + result |= mfunc ## ld (__VA_ARGS__); \ + IF_FLOAT128 (result |= mfunc ## f128 (__VA_ARGS__)); \ + result; \ }) diff --git a/sysdeps/ieee754/float128/Makefile b/sysdeps/ieee754/float128/Makefile index c07586c..166e630 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 caf2064..ef9df2d 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 0000000..12f703a --- /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 + . */ + +#include "gmp.h" +#include "gmp-impl.h" +#include +#include + +#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 0000000..79329fb --- /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 + . */ + +#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 0000000..63cc80d --- /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 + . */ + +/* 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 + +#include diff --git a/sysdeps/ieee754/float128/strtof128_l.c b/sysdeps/ieee754/float128/strtof128_l.c new file mode 100644 index 0000000..0f768a3 --- /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 + . */ + +#include + +/* Bring in potential typedef for _Float128 early for declaration below. */ +#include + +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 + +#include diff --git a/sysdeps/ieee754/float128/strtof128_nan.c b/sysdeps/ieee754/float128/strtof128_nan.c new file mode 100644 index 0000000..b9d79e3 --- /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 + . */ + +#include + +#include + +#include +#include + +#define STRTOD_NAN __strtof128_nan +#include diff --git a/sysdeps/ieee754/float128/wcstof128.c b/sysdeps/ieee754/float128/wcstof128.c new file mode 100644 index 0000000..c5a17ba --- /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 + . */ + +#include +#include + +#define USE_WIDE_CHAR 1 + +/* Bring in _Float128 typedef if needed. */ +#include + +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 0000000..670b6af --- /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 + . */ + +#include +#include + + +#define USE_WIDE_CHAR 1 + +#include + +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 0000000..abad881 --- /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 + . */ + +#include +#include +#include +#define STRTOD_NAN __wcstof128_nan +#include diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index d6b214b..84cf986 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -81,6 +81,7 @@ CFLAGS-wcstoll.c = $(strtox-CFLAGS) CFLAGS-wcstoull.c = $(strtox-CFLAGS) CFLAGS-wcstod.c = $(strtox-CFLAGS) CFLAGS-wcstold.c = $(strtox-CFLAGS) +CFLAGS-wcstof128.c = $(strtox-CFLAGS) CFLAGS-wcstof.c = $(strtox-CFLAGS) CFLAGS-wcstol_l.c = $(strtox-CFLAGS) CFLAGS-wcstoul_l.c = $(strtox-CFLAGS) @@ -88,6 +89,7 @@ CFLAGS-wcstoll_l.c = $(strtox-CFLAGS) CFLAGS-wcstoull_l.c = $(strtox-CFLAGS) CFLAGS-wcstod_l.c = $(strtox-CFLAGS) CFLAGS-wcstold_l.c = $(strtox-CFLAGS) +CFLAGS-wcstof128_l.c = $(strtox-CFLAGS) CFLAGS-wcstof_l.c = $(strtox-CFLAGS) CPPFLAGS-tst-wchar-h.c = -D_FORTIFY_SOURCE=2 diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h index 79be9fc..5be993d 100644 --- a/wcsmbs/wchar.h +++ b/wcsmbs/wchar.h @@ -28,6 +28,9 @@ # include #endif +/* Gather machine dependent type support. */ +#include + #ifdef _WCHAR_H /* Get FILE definition. */ # define __need___FILE @@ -426,6 +429,12 @@ extern long double wcstold (const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr) __THROW; #endif /* C99 */ +/* Likewise for `_Float128' when support is enabled. */ +#if __HAVE_FLOAT128 && defined __USE_GNU +extern _Float128 wcstof128 (const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr) __THROW; +#endif + /* Convert initial portion of wide string NPTR to `long int' representation. */ @@ -518,6 +527,12 @@ extern float wcstof_l (const wchar_t *__restrict __nptr, extern long double wcstold_l (const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr, __locale_t __loc) __THROW; + +# if __HAVE_FLOAT128 +extern _Float128 wcstof128_l (const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + __locale_t __loc) __THROW; +# endif #endif /* use GNU */