unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: [PATCH] Fix non-portable usage of `isinf' in `max' and `min'
Date: Wed, 02 Feb 2011 19:38:50 -0500	[thread overview]
Message-ID: <87lj1yt0it.fsf_-_@yeeloong.netris.org> (raw)
In-Reply-To: <m3bp2ut5w1.fsf@unquote.localdomain> (Andy Wingo's message of "Wed, 02 Feb 2011 23:42:54 +0100")

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]

Andy Wingo <wingo@pobox.com> 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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix non-portable usage of `isinf' in `max' and `min' --]
[-- Type: text/x-diff, Size: 2252 bytes --]

From 6801f4c8503be81c03f503520c8e2d70944f371d Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
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))
+
 \f
 
 /*
@@ -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


  reply	other threads:[~2011-02-03  0:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-02 11:25 [PATCH] Complex numbers with inexact zero imaginary part, etc Mark H Weaver
2011-02-02 20:29 ` Andy Wingo
2011-02-02 20:30 ` Andy Wingo
2011-02-02 21:36   ` Mark H Weaver
2011-02-02 22:42     ` Andy Wingo
2011-02-03  0:38       ` Mark H Weaver [this message]
2011-02-03  9:43         ` [PATCH] Fix non-portable usage of `isinf' in `max' and `min' Andy Wingo
2011-02-03 13:07         ` Ludovic Courtès
2011-02-02 20:35 ` [PATCH] Complex numbers with inexact zero imaginary part, etc Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lj1yt0it.fsf_-_@yeeloong.netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).