From b3d8a8f9fda07a0f06a24aca3667725dbc7c49b2 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Sat, 26 Jul 2008 12:39:11 -0700 Subject: [PATCH] sqrt now supports negative arguments properly. --- scheme/ikarus.numerics.ss | 18 +++++++----------- scheme/last-revision | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/scheme/ikarus.numerics.ss b/scheme/ikarus.numerics.ss index b8ed143..c1dcb40 100644 --- a/scheme/ikarus.numerics.ss +++ b/scheme/ikarus.numerics.ss @@ -2543,15 +2543,15 @@ (define sqrt (lambda (x) (cond - [(flonum? x) (foreign-call "ikrt_fl_sqrt" x)] + [(flonum? x) + (if ($fl< x 0.0) + (make-rectangular 0.0 + (foreign-call "ikrt_fl_sqrt" ($fl- 0.0 x))) + (foreign-call "ikrt_fl_sqrt" x))] [(fixnum? x) (cond [($fx< x 0) - (let-values ([(s r) (exact-integer-sqrt (- x))]) - (cond - [(eq? r 0) ($make-rectangular 0 s)] - [else - (error 'sqrt "inexact complex numbers not supported yet")]))] + (make-rectangular 0 (sqrt (- x)))] [else (let-values ([(s r) (exact-integer-sqrt x)]) (cond @@ -2576,11 +2576,7 @@ (inexact s))] [else v]))]))] [else - (let-values ([(s r) (exact-integer-sqrt (- x))]) - (cond - [(eq? r 0) (make-rectangular 0 s)] - [else - (error 'sqrt "inexact complex numbers not supported yet")]))])] + (make-rectangular 0 (sqrt (- x)))])] [(ratnum? x) ;;; FIXME: incorrect as per bug 180170 (/ (sqrt ($ratnum-n x)) (sqrt ($ratnum-d x)))] diff --git a/scheme/last-revision b/scheme/last-revision index a2e0f14..9d7a590 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1554 +1555