From patchwork Fri Oct 28 21:17:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 688636 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 3t5Gng62R2z9t1F for ; Sat, 29 Oct 2016 08:18:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=s0LFMZZP; 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:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=Sy4ByQnW/74c99PE5MpkDvcSyZLEy NzmFGP7ZxvxnbBzBLh+lC58c1XuEa5ofCQr6foM0jIYEWfAsyTJxEx3OXB8GgCdm nnUrHuXLb5QfunpZXZU8E+ySQ1OXrMAN2Vy3/XLUEOt4cCu0zYEiitT1X5G0Ekyy dQmZXdXW5sZGOw= 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:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=LH/sjLLUbF7fYaVqTfowV9SPocs=; b=s0L FMZZPfKA4lLFSbB/bxpkIeqqonrgsOGer+T5pbrLGF4GEsZVgTn+U/ijljvySfd6 tkfg0pbZdKbpQmMytvLxVdk+jmNTZ2smxQ5InVDRjpAL9rTzD0QyMOz4UuDN+V3N IhvDHZyymZytqyTU9ppIjjPTa95RKyJazF8cpHDA= Received: (qmail 118030 invoked by alias); 28 Oct 2016 21:18:09 -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 118012 invoked by uid 89); 28 Oct 2016 21:18:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=lit, snprintf X-HELO: relay1.mentorg.com Date: Fri, 28 Oct 2016 21:17:52 +0000 From: Joseph Myers To: Subject: Add SNAN, SNANF, SNANL macros [committed] Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) TS 18661-1 defines SNAN macros for signaling NaN values, suitable for use in static initializers. This patch adds them to glibc's (provided you are building with GCC 3.3 or later; no attempt is made to provide any kind of nonconforming fallback for older compilers without the __builtin_nans functions). Tested for x86_64 and x86. Committed. 2016-10-28 Joseph Myers * math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT) && __GNUC_PREREQ (3, 3)] (SNANF): New macro. [__GLIBC_USE (IEC_60559_BFP_EXT) && __GNUC_PREREQ (3, 3)] (SNAN): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT) && __GNUC_PREREQ (3, 3)] (SNANL): Likewise. * manual/arith.texi (Infinity and NaN): Document SNANF, SNAN and SNANL. * math/test-double.h (snan_value_MACRO): New macro. * math/test-float.h (snan_value_MACRO): Likewise. * math/test-ldouble.h (snan_value_MACRO): Likewise. * math/libm-test.inc (issignaling_test_data): Add tests of snan_value_MACRO. diff --git a/NEWS b/NEWS index 2da72cd..65184b1 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,8 @@ Version 2.25 * New features are added from TS 18661-1:2014: + - Signaling NaN macros: SNANF, SNAN, SNANL. + - Comparison macros: iseqsig. - Classification macros: iscanonical, issubnormal, iszero. diff --git a/manual/arith.texi b/manual/arith.texi index a5c04e4..f0f3bb4 100644 --- a/manual/arith.texi +++ b/manual/arith.texi @@ -711,6 +711,15 @@ such as by defining @code{_GNU_SOURCE}, and then you must include @file{math.h}.) @end deftypevr +@comment math.h +@comment ISO +@deftypevr Macro float SNANF +@deftypevrx Macro double SNAN +@deftypevrx Macro {long double} SNANL +These macros, defined by TS 18661-1:2014, are constant expressions for +signaling NaNs. +@end deftypevr + @w{IEEE 754} also allows for another unusual value: negative zero. This value is produced when you divide a positive number by negative infinity, or when a negative result is smaller than the limits of diff --git a/math/libm-test.inc b/math/libm-test.inc index 7106338..88420ee 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -8901,6 +8901,8 @@ static const struct test_f_i_data issignaling_test_data[] = TEST_f_b (issignaling, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_f_b (issignaling, snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), TEST_f_b (issignaling, -snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_b (issignaling, snan_value_MACRO, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_b (issignaling, -snan_value_MACRO, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), }; static void diff --git a/math/math.h b/math/math.h index 7c0c709..70d9b86 100644 --- a/math/math.h +++ b/math/math.h @@ -45,6 +45,15 @@ __BEGIN_DECLS # include #endif /* __USE_ISOC99 */ +#if __GLIBC_USE (IEC_60559_BFP_EXT) +/* Signaling NaN macros, if supported. */ +# if __GNUC_PREREQ (3, 3) +# define SNANF (__builtin_nansf ("")) +# define SNAN (__builtin_nans ("")) +# define SNANL (__builtin_nansl ("")) +# endif +#endif + /* Get the architecture specific values describing the floating-point evaluation. The following symbols will get defined: diff --git a/math/test-double.h b/math/test-double.h index b9e8cd8..e172b8f 100644 --- a/math/test-double.h +++ b/math/test-double.h @@ -27,3 +27,4 @@ #define TYPE_STR "double" #define LITM(x) x #define FTOSTR snprintf +#define snan_value_MACRO SNAN diff --git a/math/test-float.h b/math/test-float.h index e783c09..ea096c8 100644 --- a/math/test-float.h +++ b/math/test-float.h @@ -28,3 +28,4 @@ /* Use the double variants of macro constants. */ #define LITM(x) x #define FTOSTR snprintf +#define snan_value_MACRO SNANF diff --git a/math/test-ldouble.h b/math/test-ldouble.h index b877711..62c9eb8 100644 --- a/math/test-ldouble.h +++ b/math/test-ldouble.h @@ -27,3 +27,4 @@ #define LIT(x) (x ## L) #define LITM(x) x ## l #define FTOSTR snprintf +#define snan_value_MACRO SNANL