From: Kevin Ryde <user42@zip.com.au>
Subject: min,max big/real exactness
Date: Tue, 23 Mar 2004 08:43:01 +1000 [thread overview]
Message-ID: <87zna8wlje.fsf@zip.com.au> (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
reply other threads:[~2004-03-22 22:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87zna8wlje.fsf@zip.com.au \
--to=user42@zip.com.au \
/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).