From patchwork Fri Sep 1 13:56:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 22495 Received: (qmail 64475 invoked by alias); 1 Sep 2017 13:56:44 -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 64280 invoked by uid 89); 1 Sep 2017 13:56:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=100, 000, H*M:bc13 X-HELO: mail-qk0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oD8lu0WHCRs5Lm8AU1DFyPG2KuS3vzsPskGjRpzJcRE=; b=gngcWsSDl6Epz3egHB3lqpMbGmk2vxfBd7eJTQpgKn0QeYZ8xtHA5qTisY9OLshd9r ROnl2Pvk3MUNfndiMeEoDmrdZJLrCEzkfF8iEXdBifxw1RrFhf0EpXPIm5DQJqd+ZVzK pW9jlnoI88IyroRKtjd17C9bnaQPmdSZFZZvehb2vzCAX4MSVJIhTFcpnLLQdPiJMvVt VZnNe86Xzj0tsiQHwuS54WDZHRkbQI4f+O4puJ0jXHfsn3Hk9G+mnHVGk56H+JeA96CN d/kj33I34Sro5f56vgDXi9ZnIuINzPcwROUfs7FFpUV93H9rSCoBCJnmnkGcKEogsAnR drZg== X-Gm-Message-State: AHPjjUilsN6Oz8L1pNhjB0fVWgok+oAFW/2zQVbCeClLTtDr41O5BPWD CcNgnmWg+FTSyQfqtkk= X-Google-Smtp-Source: ADKCNb6Akr+kXkn28pkoQZ9JKBkb2kFeuDgsk3E0Gj4Am2cRlC+hzy3n25sPvoVhqHGXSFT8PoDwpQ== X-Received: by 10.55.217.150 with SMTP id q22mr2472080qkl.343.1504274200853; Fri, 01 Sep 2017 06:56:40 -0700 (PDT) Subject: Re: Simplify HUGE_VAL definitions [committed] To: Joseph Myers Cc: GNU C Library References: <0a429628-dfbc-9eaf-4e19-26d9cfa22bde@panix.com> From: Zack Weinberg Message-ID: <68de3d6e-7900-96a4-bc13-c5eff05fda7f@panix.com> Date: Fri, 1 Sep 2017 09:56:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: On 09/01/2017 09:24 AM, Joseph Myers wrote: > On Fri, 1 Sep 2017, Zack Weinberg wrote: > >>> Annex F requires conversions of constants (with at most DECIMAL_DIG >>> digits) to be to-nearest. (TS 18661-1 adds the FENV_ROUND pragma to >>> choose a different rounding mode for them and for certain operations.) >> >> Yes, but for any constant greater than _MAX, _MAX is >> arguably nearer to that constant than +Infinity is. > > The IEEE rounding modes (all of them) define overflow on the basis of > whether the result with normal precision but infinite exponent range would > have an exponent that's too big (and in the case of overflow, the rounded > result is determined by the rounding mode, so +Inf for to-nearest). OK, I think I get it. One more problem, which I should have thought to check earlier: 1e10000L isn't big enough if long double is 128 bits wide (which it actually appears to be on this computer): $ gcc -E -dM -xc - < /dev/null | grep -E '(DBL|LDBL|FLT[0-9]*)_MAX_EXP' #define __LDBL_MAX_EXP__ 16384 #define __DBL_MAX_EXP__ 1024 #define __FLT32_MAX_EXP__ 128 #define __FLT128_MAX_EXP__ 16384 #define __FLT_MAX_EXP__ 128 #define __FLT64_MAX_EXP__ 1024 So I propose this patch (not yet tested): --- a/math/math.h +++ b/math/math.h @@ -37,20 +37,25 @@ __BEGIN_DECLS /* Gather machine dependent type support. */ #include -/* Value returned on overflow. On all IEEE754 machines, this is - +Infinity. */ +/* Value returned on overflow. With IEEE 754 floating point, this is + +Infinity, otherwise the largest representable positive value. */ #if __GNUC_PREREQ (3, 3) # define HUGE_VAL (__builtin_huge_val ()) #else -# define HUGE_VAL 1e10000 +/* This may provoke compiler warnings, and may not be rounded to + +Infinity in all IEEE 754 rounding modes, but is the best that + can be done in ISO C while remaining a constant expression. + 100,000 is greater than the maximum exponent for all supported + floating-point formats and widths. */ +# define HUGE_VAL 1e100000 #endif #ifdef __USE_ISOC99 # if __GNUC_PREREQ (3, 3) # define HUGE_VALF (__builtin_huge_valf ()) # define HUGE_VALL (__builtin_huge_vall ()) # else -# define HUGE_VALF 1e10000f -# define HUGE_VALL 1e10000L +# define HUGE_VALF 1e100000f +# define HUGE_VALL 1e100000L # endif #endif #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)