From: Kevin Ryde <user42@zip.com.au>
Subject: scm_round_number using scm_round
Date: Mon, 17 May 2004 09:12:14 +1000 [thread overview]
Message-ID: <87k6zcvuep.fsf@zip.com.au> (raw)
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
* numbers.c (scm_round_number): For inum and big, just return x. For
real, use scm_round for problems with 2^54-1 etc covered there.
The problem that afflicted scm_round arises in the same algorithm done
with SCMs in scm_round_number. I think it can call scm_round to share
code.
[-- Attachment #2: numbers.c.round-number.diff --]
[-- Type: text/plain, Size: 832 bytes --]
--- numbers.c.~1.243.~ 2004-05-12 07:19:25.000000000 +1000
+++ numbers.c 2004-05-17 07:36:30.000000000 +1000
@@ -5007,6 +5007,15 @@
"round towards the even one.")
#define FUNC_NAME s_scm_round_number
{
+ if (SCM_INUMP (x) || SCM_BIGP (x))
+ return x;
+ else if (SCM_REALP (x))
+ return scm_make_real (scm_round (SCM_REAL_VALUE (x)));
+ else
+ {
+ /* OPTIMIZE-ME: Fraction case could be done more efficiently by a
+ single quotient+remainder division then examining to see which way
+ the rounding should go. */
SCM plus_half = scm_sum (x, exactly_one_half);
SCM result = scm_floor (plus_half);
/* Adjust so that the scm_round is towards even. */
@@ -5015,6 +5024,7 @@
return scm_difference (result, SCM_MAKINUM (1));
else
return result;
+ }
}
#undef FUNC_NAME
[-- 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-05-16 23:12 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=87k6zcvuep.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).