unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* abs allocating new realnum
@ 2003-11-14 20:23 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2003-11-14 20:23 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 159 bytes --]

        * numbers.c (scm_abs): Allocate a new real only for negatives, as done
        for bignums.
        * tests/numbers.test (abs): Add a few more tests.


[-- Attachment #2: numbers.c.abs.diff --]
[-- Type: text/plain, Size: 519 bytes --]

--- numbers.c.~1.206.~	1970-01-01 10:00:01.000000000 +1000
+++ numbers.c	2003-11-13 08:31:33.000000000 +1000
@@ -468,7 +468,14 @@
 	return x;
     }
   else if (SCM_REALP (x))
-    return scm_make_real (fabs (SCM_REAL_VALUE (x)));
+    {
+      /* note that if x is a NaN then xx<0 is false so we return x unchanged */
+      double xx = SCM_REAL_VALUE (x);
+      if (xx < 0.0)
+        return scm_make_real (-xx);
+      else
+        return x;
+    }
   else
     SCM_WTA_DISPATCH_1 (g_scm_abs, x, 1, s_scm_abs);
 }

[-- Attachment #3: numbers.test.abs.diff --]
[-- Type: text/plain, Size: 587 bytes --]

--- numbers.test.~1.36.~	1970-01-01 10:00:01.000000000 +1000
+++ numbers.test	2003-11-13 08:33:43.000000000 +1000
@@ -172,9 +172,13 @@
   (pass-if (= 1 (abs -1)))
   (pass-if (= (+ fixnum-max 1) (abs (+ fixnum-max 1))))
   (pass-if (= (+ (- fixnum-min) 1) (abs (- fixnum-min 1))))  
-  (pass-if (positive? (abs 1.0)))
-  (pass-if (positive? (abs -1.0))))
-  
+  (pass-if (= 0.0 (abs 0.0)))
+  (pass-if (= 1.0 (abs 1.0)))
+  (pass-if (= 1.0 (abs -1.0)))
+  (pass-if (nan? (abs +nan.0)))
+  (pass-if (= +inf.0 (abs +inf.0)))
+  (pass-if (= +inf.0 (abs -inf.0))))
+
 ;;;
 ;;; quotient
 ;;;

[-- 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-11-14 20:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-14 20:23 abs allocating new realnum 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).