[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
min,max big/real exactness
From: |
Kevin Ryde |
Subject: |
min,max big/real exactness |
Date: |
Tue, 23 Mar 2004 08:43:01 +1000 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) |
* 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.
--- 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))
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- min,max big/real exactness,
Kevin Ryde <=