Re: [Chicken-users] Bug in numbers egg -- log function

2012-01-10 Thread Peter Bex
On Tue, Jan 10, 2012 at 03:36:04AM +0100, Alexander Shendi wrote:
 Dear Chicken users,
 
 I have encounterd what seems to be a bug in the numbers egg. The problem
 occurs when I evaluate (log 297.0+0.1i).

Please try the attached patch (or numbers trunk, as of r25802).

#;1 (use numbers)
#;2 (log 297.0+0.1i)
5.69373219548625+0.000336700323976755i

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth
Index: numbers.scm
===
--- numbers.scm (revision 25798)
+++ numbers.scm (working copy)
@@ -1359,15 +1359,17 @@
 (define exp %exp)
 
 (define (%log x)
-  (cond
-   ((% x 0.0 'log) ; avoid calling inexact-exact on X here (to avoid 
overflow?)
-(##core#inline_allocate (C_a_i_log 4) (%exact-inexact x)))
-   ((%= x 0.0)
-(if (%exact? x)
-(log0 'log x)
-   (##core#inline_allocate (C_a_i_log 4) (%exact-inexact x
-   (else ; negative
-(%+ (%log (%magnitude x)) (* (make-complex 0 1) (%angle x))
+  (let ((type (%check-number x)))
+(cond
+ ;; avoid calling inexact-exact on X here (to avoid overflow?)
+ ((or (eq? type COMP) (% x 0.0 'log)) ; General case
+  (%+ (%log (%magnitude x)) (* (make-complex 0 1) (%angle x
+ ((eq? x 0); Exact zero?  That's undefined
+  (log0 'log x))
+ ((eq? type NONE)
+  (bad-number 'exp x))
+ (else ; Simple real number case
+  (##core#inline_allocate (C_a_i_log 4) (%exact-inexact x))
 
 (define log %log)
 
Index: tests/numbers-test.scm
===
--- tests/numbers-test.scm  (revision 25798)
+++ tests/numbers-test.scm  (working copy)
@@ -418,6 +418,13 @@
  (test log of exp = 1 1.0 (log (exp 1)))
  (test log of -1 (string-number 0.0+3.141592653589793i) (log -1))
 
+ (test log with complex number
+   (string-number 0.0+1.5707963267948966i)
+   (log (string-number +i)))
+
+ (test exp(log(x)) = x
+   (string-number 2.0-3.0i) (exp (log (string-number 2.0-3.0i
+
  (letrec ((fac (lambda (n)
  (if (zero? n)
  1
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Bug in numbers egg -- log function

2012-01-09 Thread Alexander Shendi
Dear Chicken users,

I have encounterd what seems to be a bug in the numbers egg. The problem
occurs when I evaluate (log 297.0+0.1i). I have tested this with 
the current stable release (4.7.0) on the following platforms:

OS CPU   Machine
===
OpenBSD 5.0   Loongson2F (mips64el)  Lemote Yeeloong 8089B
OpenBSD 5.0   i686 (x86) Asus eeePC 701

I have appended the two logs below. 

I have two questions:

- Is this list the proper place to report the bug?
- How do I obtain the source code of the numbers egg, so 
  I can come up with a patch?

Many thanks in advance,

Alexander Shendi

= Log for yeeloong.local (mips64el) =
Script started on Mon Jan  9 21:40:58 2012
$ csi -v

CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.0 
openbsd-unix-gnu-mips [ 64bit dload ptables ]
compiled 2011-11-13 on loongson.local (OpenBSD)

$ csi -R numbers -e '(log 297+0.1i)'

Error: (log) bad argument type - complex number has no ordering: 297.0+0.1i

Call history:

syntax  (##core#require-extension (numbers) #t)
syntax  (##core#begin (##core#begin (##core#begin 
(##sys#require (quote numbers))) (import numbers)) (##core..
syntax  (##core#begin (##core#begin (##sys#require (quote 
numbers))) (import numbers))
syntax  (##core#begin (##sys#require (quote numbers)))
syntax  (##sys#require (quote numbers))
syntax  (quote numbers)
syntax  (##core#quote numbers)
syntax  (import numbers)
syntax  (import (except scheme + - * / =   = = eqv? 
number-string string-number exp log sin cos tan at..
syntax  (##core#undefined)
syntax  (##core#undefined)
syntax  (##core#undefined)
eval(##sys#require (quote numbers))
syntax  (log 297.0+0.1i)
eval(log 297.0+0.1i)  --
$ 

Script done on Mon Jan  9 21:41:36 2012

= Log for eeepc.local (i386) 
=
Script started on Mon Jan  9 22:04:44 2012
$ csi -v

CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.0 
openbsd-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2012-01-09 on eeepc.local (OpenBSD)

$ csi -R numbers -e '(log 297.0+0.1i)'

Error: (log) bad argument type - complex number has no ordering: 297.0+0.1i

Call history:

syntax  (##core#require-extension (numbers) #t)
syntax  (##core#begin (##core#begin (##core#begin 
(##sys#require (quote numbers))) (import numbers)) (##core..
syntax  (##core#begin (##core#begin (##sys#require (quote 
numbers))) (import numbers))
syntax  (##core#begin (##sys#require (quote numbers)))
syntax  (##sys#require (quote numbers))
syntax  (quote numbers)
syntax  (##core#quote numbers)
syntax  (import numbers)
syntax  (import (except scheme + - * / =   = = eqv? 
number-string string-number exp log sin cos tan at..
syntax  (##core#undefined)
syntax  (##core#undefined)
syntax  (##core#undefined)
eval(##sys#require (quote numbers))
syntax  (log 297.0+0.1i)
eval(log 297.0+0.1i)  --
$ 

Script done on Mon Jan  9 22:05:23 2012

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users