Optimize truncate, round, floor, and ceiling
authorMark H Weaver <mhw@netris.org>
Sun, 13 Feb 2011 12:14:57 +0000 (07:14 -0500)
committerAndy Wingo <wingo@pobox.com>
Mon, 14 Feb 2011 19:31:14 +0000 (20:31 +0100)
commit8b56bcec442b203fcde509b40bd5866e62aaa111
tree9aea4b1f6ba7adc9cce70beefa39493cd38abda9
parent8f9da3406b507058475db2e8dde6fbb50d12faf7
Optimize truncate, round, floor, and ceiling

* libguile/numbers.c (scm_c_truncate): Use ceil (x) instead of
  -floor (-x).

  (scm_truncate_number): Implement directly instead of by checking the
  sign and using scm_floor or scm_ceiling.  Use scm_truncate_quotient
  for fractions.  Make extensible, so that new number types implemented
  in GOOPS will be able to do the job more efficiently, since it is
  often easier to implement truncate than floor or ceiling.

  (scm_round_number): Optimize fractions case by using
  scm_round_quotient.  Make extensible, so that new number types
  implemented in GOOPS will be able to do the job efficiently.

  (scm_floor, scm_ceiling): Optimize fractions case by using
  scm_floor_quotient and scm_ceiling_quotient, respectively.

* test-suite/tests/numbers.test: Add test cases.
libguile/numbers.c
test-suite/tests/numbers.test