unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* min,max big/real exactness
@ 2004-03-22 22:43 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2004-03-22 22:43 UTC (permalink / raw)


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

        * numbers.c (scm_min, scm_max): Correction to big/real and real/big,
        return inexact as required by r5rs.

        * tests/numbers.test (min, max): Check inexactness of big/real and
        real/big combinations, collect up tests under arg types for clarity.

The inexactness of inum/real and real/inum is exercised by r4rs.test,
but big combos slipped through.


[-- Attachment #2: numbers.c.min-max-inexact.diff --]
[-- Type: text/plain, Size: 1990 bytes --]

--- numbers.c.~1.224.~	2004-02-22 08:02:53.000000000 +1000
+++ numbers.c	2004-03-22 18:46:23.000000000 +1000
@@ -3442,13 +3442,10 @@
 	}
       else if (SCM_REALP (y))
 	{
+          /* if y==NaN then xx>yy is false, so we return the NaN y */
+          double xx = scm_i_big2dbl (x);
 	  double yy = SCM_REAL_VALUE (y);
-	  int cmp;
-	  if (xisnan (yy))
-	    return y;
-	  cmp = xmpz_cmp_d (SCM_I_BIG_MPZ (x), yy);
-	  scm_remember_upto_here_1 (x);
-	  return (cmp > 0) ? x : y;
+	  return (xx > yy ? scm_make_real (xx) : y);
 	}
       else if (SCM_FRACTIONP (y))
 	{
@@ -3471,13 +3468,10 @@
 	}
       else if (SCM_BIGP (y))
 	{
+          /* if x==NaN then yy>xx is false, so we return the NaN x */
 	  double xx = SCM_REAL_VALUE (x);
-	  int cmp;
-	  if (xisnan (xx))
-	    return x;
-	  cmp = xmpz_cmp_d (SCM_I_BIG_MPZ (y), xx);
-	  scm_remember_upto_here_1 (y);
-	  return (cmp < 0) ? x : y;
+          double yy = scm_i_big2dbl (y);
+	  return (yy > xx ? scm_make_real (yy) : x);
 	}
       else if (SCM_REALP (y))
 	{
@@ -3591,13 +3585,10 @@
 	}
       else if (SCM_REALP (y))
 	{
+          /* if y==NaN then xx<yy is false, so we return the NaN y */
+          double xx = scm_i_big2dbl (x);
 	  double yy = SCM_REAL_VALUE (y);
-	  int cmp;
-	  if (xisnan (yy))
-	    return y;
-	  cmp = xmpz_cmp_d (SCM_I_BIG_MPZ (x), yy);
-	  scm_remember_upto_here_1 (x);
-	  return (cmp > 0) ? y : x;
+	  return (xx < yy ? scm_make_real (xx) : y);
 	}
       else if (SCM_FRACTIONP (y))
 	{
@@ -3620,13 +3611,10 @@
 	}
       else if (SCM_BIGP (y))
 	{
-	  double xx = SCM_REAL_VALUE (x);
-	  int cmp;
-	  if (xisnan (xx))
-	    return x;
-	  cmp = xmpz_cmp_d (SCM_I_BIG_MPZ (y), xx);
-	  scm_remember_upto_here_1 (y);
-	  return (cmp < 0) ? y : x;
+          /* if x==NaN then yy<xx is false, so we return the NaN x */
+          double xx = SCM_REAL_VALUE (x);
+          double yy = scm_i_big2dbl (y);
+	  return (yy < xx ? scm_make_real (yy) : x);
 	}
       else if (SCM_REALP (y))
 	{

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-03-22 22:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-22 22:43 min,max big/real exactness Kevin Ryde

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).