Merge branch 'master' into boehm-demers-weiser-gc
[bpt/guile.git] / libguile / numbers.c
index aad0504..0452e43 100644 (file)
 
  */
 
-/* tell glibc (2.3) to give prototype for C99 trunc(), csqrt(), etc */
-#define _GNU_SOURCE
-
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
@@ -163,20 +160,24 @@ xisnan (double x)
 }
 
 #if defined (GUILE_I)
+#if HAVE_COMPLEX_DOUBLE
+
 /* For an SCM object Z which is a complex number (ie. satisfies
    SCM_COMPLEXP), return its value as a C level "complex double". */
 #define SCM_COMPLEX_VALUE(z)                                    \
   (SCM_COMPLEX_REAL (z) + GUILE_I * SCM_COMPLEX_IMAG (z))
-#endif
+
+static inline SCM scm_from_complex_double (complex double z) SCM_UNUSED;
 
 /* Convert a C "complex double" to an SCM value. */
-#if HAVE_COMPLEX_DOUBLE
-static SCM
+static inline SCM
 scm_from_complex_double (complex double z)
 {
   return scm_c_make_rectangular (creal (z), cimag (z));
 }
+
 #endif /* HAVE_COMPLEX_DOUBLE */
+#endif /* GUILE_I */
 
 \f
 
@@ -5327,8 +5328,9 @@ scm_c_make_rectangular (double re, double im)
   else
     {
       SCM z;
-      SCM_NEWSMOB (z, scm_tc16_complex, scm_gc_malloc (sizeof (scm_t_complex),
-                                                      "complex"));
+      SCM_NEWSMOB (z, scm_tc16_complex,
+                  scm_gc_malloc_pointerless (sizeof (scm_t_complex),
+                                             "complex"));
       SCM_COMPLEX_REAL (z) = re;
       SCM_COMPLEX_IMAG (z) = im;
       return z;
@@ -5595,8 +5597,18 @@ SCM_DEFINE (scm_inexact_to_exact, "inexact->exact", 1, 0, 0,
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_rationalize, "rationalize", 2, 0, 0, 
-            (SCM x, SCM err),
-           "Return an exact number that is within @var{err} of @var{x}.")
+            (SCM x, SCM eps),
+           "Returns the @emph{simplest} rational number differing\n"
+           "from @var{x} by no more than @var{eps}.\n"
+           "\n"
+           "As required by @acronym{R5RS}, @code{rationalize} only returns an\n"
+           "exact result when both its arguments are exact.  Thus, you might need\n"
+           "to use @code{inexact->exact} on the arguments.\n"
+           "\n"
+           "@lisp\n"
+           "(rationalize (inexact->exact 1.2) 1/100)\n"
+           "@result{} 6/5\n"
+           "@end lisp")
 #define FUNC_NAME s_scm_rationalize
 {
   if (SCM_I_INUMP (x))
@@ -5628,7 +5640,7 @@ SCM_DEFINE (scm_rationalize, "rationalize", 2, 0, 0,
         converges after less than a dozen iterations.
       */
 
-      err = scm_abs (err);
+      eps = scm_abs (eps);
       while (++i < 1000000)
        {
          a = scm_sum (scm_product (a1, tt), a2);    /* a = a1*tt + a2 */
@@ -5636,11 +5648,11 @@ SCM_DEFINE (scm_rationalize, "rationalize", 2, 0, 0,
          if (scm_is_false (scm_zero_p (b)) &&         /* b != 0 */
              scm_is_false 
              (scm_gr_p (scm_abs (scm_difference (ex, scm_divide (a, b))),
-                        err)))                      /* abs(x-a/b) <= err */
+                        eps)))                      /* abs(x-a/b) <= eps */
            {
              SCM res = scm_sum (int_part, scm_divide (a, b));
              if (scm_is_false (scm_exact_p (x))
-                 || scm_is_false (scm_exact_p (err)))
+                 || scm_is_false (scm_exact_p (eps)))
                return scm_exact_to_inexact (res);
              else
                return res;