From owner-svn-src-head@freebsd.org Tue Aug 29 22:32:30 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED575DE75F5; Tue, 29 Aug 2017 22:32:30 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8DA6F73B04; Tue, 29 Aug 2017 22:32:30 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7TMWTM5069987; Tue, 29 Aug 2017 22:32:29 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7TMWTIt069984; Tue, 29 Aug 2017 22:32:29 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201708292232.v7TMWTIt069984@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 29 Aug 2017 22:32:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323003 - head/lib/msun/src X-SVN-Group: head X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: head/lib/msun/src X-SVN-Commit-Revision: 323003 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Aug 2017 22:32:31 -0000 Author: rlibby Date: Tue Aug 29 22:32:29 2017 New Revision: 323003 URL: https://svnweb.freebsd.org/changeset/base/323003 Log: lib/msun: avoid referring to broken LDBL_MAX LDBL_MAX is broken on i386: https://lists.freebsd.org/pipermail/freebsd-numerics/2012-September/000288.html Gcc has produced +Infinity for LDBL_MAX on i386 and amd64 with -m32 for some time, and newer versions of gcc are now warning that the "floating constant exceeds range of 'long double'". Avoid this by referring to proxy values instead. Reviewed by: bde Approved by: markj (mentor) Sponsored by: Dell EMC Isilon Modified: head/lib/msun/src/catrig.c head/lib/msun/src/catrigl.c head/lib/msun/src/s_csqrtl.c Modified: head/lib/msun/src/catrig.c ============================================================================== --- head/lib/msun/src/catrig.c Tue Aug 29 22:24:22 2017 (r323002) +++ head/lib/msun/src/catrig.c Tue Aug 29 22:32:29 2017 (r323003) @@ -469,8 +469,13 @@ clog_for_large_values(double complex z) /* * Avoid overflow in hypot() when x and y are both very large. - * Divide x and y by E, and then add 1 to the logarithm. This depends - * on E being larger than sqrt(2). + * Divide x and y by E, and then add 1 to the logarithm. This + * depends on E being larger than sqrt(2), since the return value of + * hypot cannot overflow if neither argument is greater in magnitude + * than 1/sqrt(2) of the maximum value of the return type. Likewise + * this determines the necessary threshold for using this method + * (however, actually use 1/2 instead as it is simpler). + * * Dividing by E causes an insignificant loss of accuracy; however * this method is still poor since it is uneccessarily slow. */ Modified: head/lib/msun/src/catrigl.c ============================================================================== --- head/lib/msun/src/catrigl.c Tue Aug 29 22:24:22 2017 (r323002) +++ head/lib/msun/src/catrigl.c Tue Aug 29 22:32:29 2017 (r323003) @@ -57,10 +57,15 @@ __FBSDID("$FreeBSD$"); #undef signbit #define signbit(x) (__builtin_signbitl(x)) +#if LDBL_MAX_EXP != 0x4000 +#error "Unsupported long double format" +#endif + static const long double A_crossover = 10, B_crossover = 0.6417, FOUR_SQRT_MIN = 0x1p-8189L, +HALF_MAX = 0x1p16383L, QUARTER_SQRT_MAX = 0x1p8189L, RECIP_EPSILON = 1 / LDBL_EPSILON, SQRT_MIN = 0x1p-8191L; @@ -307,7 +312,7 @@ clog_for_large_values(long double complex z) ay = t; } - if (ax > LDBL_MAX / 2) + if (ax > HALF_MAX) return (CMPLXL(logl(hypotl(x / m_e, y / m_e)) + 1, atan2l(y, x))); Modified: head/lib/msun/src/s_csqrtl.c ============================================================================== --- head/lib/msun/src/s_csqrtl.c Tue Aug 29 22:24:22 2017 (r323002) +++ head/lib/msun/src/s_csqrtl.c Tue Aug 29 22:32:29 2017 (r323003) @@ -42,8 +42,16 @@ __FBSDID("$FreeBSD$"); */ #pragma STDC CX_LIMITED_RANGE ON -/* We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). */ -#define THRESH (LDBL_MAX / 2.414213562373095048801688724209698L) +/* + * We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). + * Rather than determining the fully precise value at which we might + * overflow, just use a threshold of approximately LDBL_MAX / 4. + */ +#if LDBL_MAX_EXP != 0x4000 +#error "Unsupported long double format" +#else +#define THRESH 0x1p16382L +#endif long double complex csqrtl(long double complex z)