From: Kevin Ryde <user42@zip.com.au>
Subject: angle and scm_flo0
Date: Fri, 18 Jul 2003 09:45:42 +1000 [thread overview]
Message-ID: <87fzl41zvd.fsf@zip.com.au> (raw)
[-- Attachment #1: Type: text/plain, Size: 550 bytes --]
To save a bit of consing and calls to atan2,
* numbers.c (scm_angle): Use scm_flo0 for non-negative inum, bignum
and real.
I guess the same can be done for negatives, returning pi. Would
scm_sys_protects be the right place to add an scm_flo_pi? I see
abs_most_negative_fixnum uses scm_permanent_object instead.
For the actual pi value, I guess there'd be a choice between M_PI and
the return from atan2(0.0,-1.0). The two ought to be the same of
course. Maybe use the constant and have one of the tests see that
atan2 agrees.
[-- Attachment #2: numbers.c.angle-flo0.diff --]
[-- Type: text/plain, Size: 851 bytes --]
--- numbers.c.~1.193.~ 2003-07-08 10:28:38.000000000 +1000
+++ numbers.c 2003-07-17 10:10:52.000000000 +1000
@@ -3947,7 +3947,7 @@
{
if (SCM_INUMP (z)) {
if (SCM_INUM (z) >= 0) {
- return scm_make_real (atan2 (0.0, 1.0));
+ return scm_flo0;
} else {
return scm_make_real (atan2 (0.0, -1.0));
}
@@ -3957,10 +3957,13 @@
if (sgn < 0) {
return scm_make_real (atan2 (0.0, -1.0));
} else {
- return scm_make_real (atan2 (0.0, 1.0));
+ return scm_flo0;
}
} else if (SCM_REALP (z)) {
- return scm_make_real (atan2 (0.0, SCM_REAL_VALUE (z)));
+ if (SCM_REAL_VALUE (z) >= 0)
+ return scm_flo0;
+ else
+ return scm_make_real (atan2 (0.0, -1.0));
} else if (SCM_COMPLEXP (z)) {
return scm_make_real (atan2 (SCM_COMPLEX_IMAG (z), SCM_COMPLEX_REAL (z)));
} else {
[-- Attachment #3: angle.test --]
[-- Type: text/plain, Size: 450 bytes --]
(with-test-prefix "angle"
(define pi 3.14159265358979323846)
(define (almost= x y)
(> 0.01 (magnitude (- x y))))
(pass-if "inum +ve" (= 0 (angle 1)))
(pass-if "inum -ve" (almost= pi (angle -1)))
(pass-if "bignum +ve" (= 0 (angle (1+ fixnum-max))))
(pass-if "bignum -ve" (almost= pi (angle (1- fixnum-min))))
(pass-if "flonum +ve" (= 0 (angle 1.5)))
(pass-if "flonum -ve" (almost= pi (angle -1.5))))
[-- Attachment #4: 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:[~2003-07-17 23:45 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=87fzl41zvd.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).