unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* angle and scm_flo0
@ 2003-07-17 23:45 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2003-07-17 23:45 UTC (permalink / 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

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

only message in thread, other threads:[~2003-07-17 23:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-17 23:45 angle and scm_flo0 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).