~peter-pearse/ubuntu/natty/guile-1.8/prop001

« back to all changes in this revision

Viewing changes to libguile/numbers.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2009-06-04 19:01:38 UTC
  • mfrom: (8.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090604190138-1ao3t6sj31cqvcfe
Tags: 1.8.6+1-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build with -Wno-error.
  - Build with thread support. Some guile-using programs like autogen need it.
  - Add debian/guile-1.8-libs.shlibs: Thread support breaks ABI, bump the soname.
* Dropped changes:
  - libltdl3-dev -> libltdl7-dev: current libltdl-dev Provides: both.
  - debian/patches/libtool-ftbfs.diff: integrated upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
 */
42
42
 
43
 
/* tell glibc (2.3) to give prototype for C99 trunc(), csqrt(), etc */
44
 
#define _GNU_SOURCE
45
 
 
46
 
#if HAVE_CONFIG_H
 
43
#ifdef HAVE_CONFIG_H
47
44
#  include <config.h>
48
45
#endif
49
46
 
1025
1022
scm_gcd (SCM x, SCM y)
1026
1023
{
1027
1024
  if (SCM_UNBNDP (y))
1028
 
    return SCM_UNBNDP (x) ? SCM_INUM0 : x;
 
1025
    return SCM_UNBNDP (x) ? SCM_INUM0 : scm_abs (x);
1029
1026
  
1030
1027
  if (SCM_I_INUMP (x))
1031
1028
    {
5599
5596
#undef FUNC_NAME
5600
5597
 
5601
5598
SCM_DEFINE (scm_rationalize, "rationalize", 2, 0, 0, 
5602
 
            (SCM x, SCM err),
5603
 
            "Return an exact number that is within @var{err} of @var{x}.")
 
5599
            (SCM x, SCM eps),
 
5600
            "Returns the @emph{simplest} rational number differing\n"
 
5601
            "from @var{x} by no more than @var{eps}.\n"
 
5602
            "\n"
 
5603
            "As required by @acronym{R5RS}, @code{rationalize} only returns an\n"
 
5604
            "exact result when both its arguments are exact.  Thus, you might need\n"
 
5605
            "to use @code{inexact->exact} on the arguments.\n"
 
5606
            "\n"
 
5607
            "@lisp\n"
 
5608
            "(rationalize (inexact->exact 1.2) 1/100)\n"
 
5609
            "@result{} 6/5\n"
 
5610
            "@end lisp")
5604
5611
#define FUNC_NAME s_scm_rationalize
5605
5612
{
5606
5613
  if (SCM_I_INUMP (x))
5632
5639
         converges after less than a dozen iterations.
5633
5640
      */
5634
5641
 
5635
 
      err = scm_abs (err);
 
5642
      eps = scm_abs (eps);
5636
5643
      while (++i < 1000000)
5637
5644
        {
5638
5645
          a = scm_sum (scm_product (a1, tt), a2);    /* a = a1*tt + a2 */
5640
5647
          if (scm_is_false (scm_zero_p (b)) &&         /* b != 0 */
5641
5648
              scm_is_false 
5642
5649
              (scm_gr_p (scm_abs (scm_difference (ex, scm_divide (a, b))),
5643
 
                         err)))                      /* abs(x-a/b) <= err */
 
5650
                         eps)))                      /* abs(x-a/b) <= eps */
5644
5651
            {
5645
5652
              SCM res = scm_sum (int_part, scm_divide (a, b));
5646
5653
              if (scm_is_false (scm_exact_p (x))
5647
 
                  || scm_is_false (scm_exact_p (err)))
 
5654
                  || scm_is_false (scm_exact_p (eps)))
5648
5655
                return scm_exact_to_inexact (res);
5649
5656
              else
5650
5657
                return res;