From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Fix non-portable usage of `isinf' in `max' and `min' Date: Wed, 02 Feb 2011 19:38:50 -0500 Message-ID: <87lj1yt0it.fsf_-_@yeeloong.netris.org> References: <87zkqeu19q.fsf@yeeloong.netris.org> <87pqrat8yl.fsf@yeeloong.netris.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1296693560 8141 80.91.229.12 (3 Feb 2011 00:39:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 3 Feb 2011 00:39:20 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Feb 03 01:39:13 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PknE9-0005qq-Ga for guile-devel@m.gmane.org; Thu, 03 Feb 2011 01:39:13 +0100 Original-Received: from localhost ([127.0.0.1]:47184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PknE9-0008Le-2k for guile-devel@m.gmane.org; Wed, 02 Feb 2011 19:39:13 -0500 Original-Received: from [140.186.70.92] (port=56389 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PknE1-0008Jh-Ls for guile-devel@gnu.org; Wed, 02 Feb 2011 19:39:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PknE0-0004XL-0z for guile-devel@gnu.org; Wed, 02 Feb 2011 19:39:05 -0500 Original-Received: from world.peace.net ([216.204.32.208]:34314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PknDz-0004XD-RH for guile-devel@gnu.org; Wed, 02 Feb 2011 19:39:03 -0500 Original-Received: from ip68-9-118-38.ri.ri.cox.net ([68.9.118.38] helo=freedomincluded) by world.peace.net with esmtpa (Exim 4.69) (envelope-from ) id 1PknDt-0006C1-OY; Wed, 02 Feb 2011 19:38:57 -0500 Original-Received: from mhw by freedomincluded with local (Exim 4.69) (envelope-from ) id 1PknDr-0006DJ-Rj; Wed, 02 Feb 2011 19:38:55 -0500 In-Reply-To: (Andy Wingo's message of "Wed, 02 Feb 2011 23:42:54 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 216.204.32.208 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11525 Archived-At: --=-=-= Andy Wingo writes: > BTW: did you see the failures on darwin? > > http://hydra.nixos.org/build/882506/nixlog/1 > > Seems there were errors in: > > FAIL: numbers.test: max: infinities and NaNs: (real-nan? (max +nan.0 -inf.0)) > FAIL: numbers.test: max: infinities and NaNs: (real-nan? (max -inf.0 +nan.0)) > FAIL: numbers.test: min: infinities and NaNs: (eqv? -inf.0 (min -inf.0 +nan.0)) > FAIL: numbers.test: min: infinities and NaNs: (eqv? -inf.0 (min +nan.0 -inf.0)) Ah, I was using a non-portable extension of isinf(x) to determine the sign of the infinity. This patch should fix it. Thanks, Mark --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-non-portable-usage-of-isinf-in-max-and-min.patch Content-Description: Fix non-portable usage of `isinf' in `max' and `min' >From 6801f4c8503be81c03f503520c8e2d70944f371d Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 2 Feb 2011 19:32:16 -0500 Subject: [PATCH] Fix non-portable usage of `isinf' in `max' and `min' * numbers.c: Add new macros DOUBLE_IS_POSITIVE_INFINITY and DOUBLE_IS_NEGATIVE_INFINITY. (scm_max, scm_min): Use the new macros to detect particular infinities. Previously we checked the return value of `isinf' to determine the sign of the infinity, but that is not portable. --- libguile/numbers.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libguile/numbers.c b/libguile/numbers.c index 18d5755..3be4478 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -83,6 +83,11 @@ typedef scm_t_signed_bits scm_t_inum; TODO: if it's available, use C99's isfinite(x) instead */ #define DOUBLE_IS_FINITE(x) (!isinf(x) && !isnan(x)) +/* On some platforms, isinf(x) returns 0, 1 or -1, indicating the sign + of the infinity, but other platforms return a boolean only. */ +#define DOUBLE_IS_POSITIVE_INFINITY(x) (isinf(x) && ((x) > 0)) +#define DOUBLE_IS_NEGATIVE_INFINITY(x) (isinf(x) && ((x) < 0)) + /* @@ -5251,9 +5256,9 @@ scm_max (SCM x, SCM y) /* If neither (xx > yy) nor (xx < yy), then either they're equal or one is a NaN */ else if (SCM_UNLIKELY (isnan (xx))) - return (isinf (yy) == 1) ? y : x; + return DOUBLE_IS_POSITIVE_INFINITY (yy) ? y : x; else if (SCM_UNLIKELY (isnan (yy))) - return (isinf (xx) == 1) ? x : y; + return DOUBLE_IS_POSITIVE_INFINITY (xx) ? x : y; /* xx == yy, but handle signed zeroes properly */ else if (double_is_non_negative_zero (yy)) return y; @@ -5411,9 +5416,9 @@ scm_min (SCM x, SCM y) /* If neither (xx < yy) nor (xx > yy), then either they're equal or one is a NaN */ else if (SCM_UNLIKELY (isnan (xx))) - return (isinf (yy) == -1) ? y : x; + return DOUBLE_IS_NEGATIVE_INFINITY (yy) ? y : x; else if (SCM_UNLIKELY (isnan (yy))) - return (isinf (xx) == -1) ? x : y; + return DOUBLE_IS_NEGATIVE_INFINITY (xx) ? x : y; /* xx == yy, but handle signed zeroes properly */ else if (double_is_non_negative_zero (xx)) return y; -- 1.5.6.5 --=-=-=--