From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: magnitude and make-polar Date: Sat, 05 Jul 2003 10:02:23 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87el15suwg.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1057363430 28994 80.91.224.249 (5 Jul 2003 00:03:50 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 5 Jul 2003 00:03:50 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jul 05 02:03:49 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19YaWq-0007XU-00 for ; Sat, 05 Jul 2003 02:03:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19YaX8-0002Cm-UA for guile-devel@m.gmane.org; Fri, 04 Jul 2003 20:04:06 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19YaWB-0001o5-Ne for guile-devel@gnu.org; Fri, 04 Jul 2003 20:03:07 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19YaVv-0001T2-1c for guile-devel@gnu.org; Fri, 04 Jul 2003 20:02:51 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19YaVi-00018p-4J for guile-devel@gnu.org; Fri, 04 Jul 2003 20:02:38 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h6502XZY008684 for ; Sat, 5 Jul 2003 10:02:33 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h6502XQg008850 for ; Sat, 5 Jul 2003 10:02:33 +1000 (EST) Original-Received: from localhost (ppp124.dyn228.pacific.net.au [203.143.228.124]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h6502Vnh010329 for ; Sat, 5 Jul 2003 10:02:31 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19YaVT-000366-00; Sat, 05 Jul 2003 10:02:23 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2591 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2591 --=-=-= * numbers.c (s_scm_make_polar): Use sincos, when available. (scm_magnitude): Use hypot. * configure.in (AC_CHECK_FUNCS): Add sincos. * tests/numbers.test (make-polar, magnitude): Add tests. glibc sincos is supposedly more efficient than separate sin and cos calls. hypot should give greater accuracy than a sqrt expression. It dates back at least to v7 unix and so shouldn't need a configure test. --=-=-= Content-Disposition: attachment; filename=numbers.c.sh.diff --- numbers.c.~1.192.~ 2003-06-21 10:06:44.000000000 +1000 +++ numbers.c 2003-07-01 17:08:54.000000000 +1000 @@ -3852,8 +3852,15 @@ #define FUNC_NAME s_scm_make_polar { struct dpair xy; + double s, c; scm_two_doubles (x, y, FUNC_NAME, &xy); - return scm_make_complex (xy.x * cos (xy.y), xy.x * sin (xy.y)); +#if HAVE_SINCOS + sincos (xy.y, &s, &c); +#else + s = sin (xy.y); + c = cos (xy.y); +#endif + return scm_make_complex (xy.x * c, xy.x * s); } #undef FUNC_NAME @@ -3925,9 +3932,7 @@ } else if (SCM_REALP (z)) { return scm_make_real (fabs (SCM_REAL_VALUE (z))); } else if (SCM_COMPLEXP (z)) { - double r = SCM_COMPLEX_REAL (z); - double i = SCM_COMPLEX_IMAG (z); - return scm_make_real (sqrt (i * i + r * r)); + return scm_make_real (hypot (SCM_COMPLEX_REAL (z), SCM_COMPLEX_IMAG (z))); } else { SCM_WTA_DISPATCH_1 (g_magnitude, z, SCM_ARG1, s_magnitude); } --=-=-= Content-Disposition: attachment; filename=configure.in.sh.diff --- configure.in.~1.222.~ 2003-06-21 10:15:31.000000000 +1000 +++ configure.in 2003-07-01 17:18:45.000000000 +1000 @@ -759,10 +759,12 @@ AC_CHECK_HEADERS(floatingpoint.h ieeefp.h nan.h) -# asinh, acosh, atanh and trunc (all in -lm) are only C99 standard and older -# systems generally don't have them. +# Reasons for testing: +# asinh, acosh, atanh, trunc - C99 standard, generally not available on +# older systems +# sincos - GLIBC extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite isinf isnan trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite isinf isnan sincos trunc) # When testing for the presence of alloca, we need to add alloca.o # explicitly to LIBOBJS to make sure that it is translated to --=-=-= Content-Disposition: attachment; filename=numbers.test.sh.diff --- numbers.test.~1.26.~ 2003-06-21 10:17:40.000000000 +1000 +++ numbers.test 2003-07-01 17:06:53.000000000 +1000 @@ -1940,6 +1940,21 @@ ;;; make-polar ;;; +(with-test-prefix "make-polar" + (define pi 3.14159265358979323846) + (define (almost= x y) + (> 0.01 (magnitude (- x y)))) + + (pass-if (= 0 (make-polar 0 0))) + (pass-if (= 0 (make-polar 0 123.456))) + (pass-if (= 1 (make-polar 1 0))) + (pass-if (= -1 (make-polar -1 0))) + + (pass-if (almost= 0+i (make-polar 1 (* 0.5 pi)))) + (pass-if (almost= -1 (make-polar 1 (* 1.0 pi)))) + (pass-if (almost= 0-i (make-polar 1 (* 1.5 pi)))) + (pass-if (almost= 1 (make-polar 1 (* 2.0 pi))))) + ;;; ;;; real-part ;;; @@ -1952,6 +1967,17 @@ ;;; magnitude ;;; +(with-test-prefix "magnitude" + (pass-if (= 0 (magnitude 0))) + (pass-if (= 1 (magnitude 1))) + (pass-if (= 1 (magnitude -1))) + (pass-if (= 1 (magnitude 0+i))) + (pass-if (= 1 (magnitude 0-i))) + (pass-if (= 5 (magnitude 3+4i))) + (pass-if (= 5 (magnitude 3-4i))) + (pass-if (= 5 (magnitude -3+4i))) + (pass-if (= 5 (magnitude -3-4i)))) + ;;; ;;; angle ;;; --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--