summaryrefslogtreecommitdiff
path: root/module/rnrs/arithmetic
AgeCommit message (Collapse)AuthorFilesLines
2016-06-21Fix fixnum-range changes in R6RS fixnum bitopsAndy Wingo1-3/+25
* module/rnrs/arithmetic/fixnums.scm (fxcopy-bit, fxbit-field) (fxcopy-bit-field, fxarithmetic-shift) (fxarithmetic-shift-left, fx-arithmetic-shift-right) (fxrotate-bit-field, fxreverse-bit-field): Enforce range on amount by which to shift. Fixes #14917. * test-suite/tests/r6rs-arithmetic-fixnums.test ("fxarithmetic-shift-left"): Update test to not shift left by a negative amount.
2013-08-09Fix numerator and denominator handling of signed zeroes and infinities.Mark H Weaver1-13/+2
* libguile/numbers.c (scm_numerator, scm_denominator): Handle signed zeroes and infinities in accordance with the corresponding R6RS flonum procedures. * module/rnrs/arithmetic/flonums.scm (flnumerator, fldenominator): Remove special handling of infinities. * test-suite/tests/numbers.test (numerator, denominator): Add tests. Convert existing tests to use 'pass-if-equal'. * test-suite/tests/r6rs-arithmetic-flonums.test (flnumerator): Fix broken test of (flnumerator -0.0).
2013-07-21Optimize R6RS bitwise operators.Mark H Weaver1-59/+22
* module/rnrs/arithmetic/bitwise.scm (bitwise-if, bitwise-length, bitwise-first-bit-set, bitwise-bit-field, bitwise-reverse-bit-field): Replace these with aliases to the identical SRFI-60 operators 'bitwise-if', 'integer-length', 'first-set-bit', 'bit-field', and 'reverse-bit-field'. (bitwise-copy-bit, bitwise-copy-bit-field, bitwise-rotate-bit-field): Reimplement these based upon the similar SRFI-60 operators 'copy-bit', 'copy-bit-field', and 'rotate-bit-field'. * test-suite/tests/r6rs-arithmetic-bitwise.test (bitwise-copy-bit): Fix test to conform to the specification, which requires the third argument to be either 0 or 1. * test-suite/tests/r6rs-arithmetic-fixnums.test (fxcopy-bit): Fix test to conform to the specification, which requires the third argument to be either 0 or 1.
2013-07-16Fix R6RS 'fixnum-width'.Mark H Weaver1-2/+5
Fixes <http://bugs.gnu.org/14879>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/fixnums.scm (fixnum-width): Rewrite to avoid inexact arithmetic, and correct the off-by-one error. * test-suite/tests/r6rs-arithmetic-fixnums.test (fixnum-width): Add tests.
2013-07-16Update copyright dates of recently-changed R6RS bitwise/flonums files.Mark H Weaver2-2/+2
* module/rnrs/arithmetic/bitwise.scm: module/rnrs/arithmetic/flonums.scm: test-suite/tests/r6rs-arithmetic-bitwise.test: test-suite/tests/r6rs-arithmetic-flonums.test: Add 2013 to the copyright dates.
2013-07-16Fix 'fxbit-count' for negative arguments.Mark H Weaver1-2/+7
Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/fixnums.scm (fxbit-count): If the argument is negative, return the 'bitwise-not' of the result of 'logcount', as per R6RS. Previously, 'fxbit-count' was identical to 'logcount'. * test-suite/tests/r6rs-arithmetic-fixnums.test (fxbit-count): Add test.
2013-07-16Flonum operations always return flonums.Mark H Weaver1-13/+26
Fixes <http://bugs.gnu.org/14871>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/flonums.scm (ensure-flonum): New procedure. (fllog): Rewrite using case-lambda. Handle negative zeroes. Use 'ensure-flonum'. (flatan): Rewrite using case-lambda. (flasin, flacos, flsqrt, flexpt): Use 'ensure-flonum'. * test-suite/tests/r6rs-arithmetic-flonums.test (fllog, flasin, flacos, flsqrt, flexpt): Add tests.
2013-07-16flfinite? applied to a NaN returns false.Mark H Weaver1-1/+1
Fixes <http://bugs.gnu.org/14868>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/flonums.scm (flfinite?): If the argument is a NaN, return false. * test-suite/tests/r6rs-arithmetic-flonums.test (flfinite?): Add test.
2013-07-16flonum? returns false for complex number objects.Mark H Weaver1-1/+1
Fixes <http://bugs.gnu.org/14866>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/flonums.scm (flonum?): Use 'real?' instead of 'number?'. * test-suite/tests/r6rs-arithmetic-flonums.test (flonum?): Add tests.
2013-07-16Allow fl+ and fl* to accept zero arguments.Mark H Weaver1-8/+6
Fixes <http://bugs.gnu.org/14869>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/flonums.scm (fl+, fl*): Accept zero arguments. * test-suite/tests/r6rs-arithmetic-flonums.test (fl+, fl*): Add tests.
2013-07-14Fix 'bitwise-bit-count' for negative arguments.Mark H Weaver1-1/+5
Fixes <http://bugs.gnu.org/14864>. Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/bitwise.scm (bitwise-bit-count): If the argument is negative, return the 'bitwise-not' of the result of 'logcount', as per R6RS. Previously, 'bitwise-bit-count' was identical to 'logcount'.
2011-04-13(rnrs arithmetic fixnums) fixnum? export a procedure againAndy Wingo1-7/+12
* module/rnrs/arithmetic/fixnums.scm (fixnum?): Restore this export to be a procedure, not syntax. (inline-fixnum?): This is what fixnum? was. Use it internally.
2011-04-08Implement R6RS' `fixnum?' in a smarter wayAndreas Rottmann1-7/+6
* module/rnrs/arithmetic/fixnums.scm (fixnum?): Implemented using bit-twiddling, and using `define-inlinable'.
2011-04-04Several optimizations for R6RS fixnum arithmeticAndreas Rottmann1-45/+41
* module/rnrs/arithmetic/fixnums.scm (assert-fixnum): Is now a macro. (assert-fixnums): New procedure checking a the elements of a list for fixnum-ness. All callers applying `assert-fixnum' to a list now changed to use this procedure. * module/rnrs/arithmetic/fixnums.scm (define-fxop*): New for defining n-ary inlinable special-casing the binary case using `case-lambda'. All applicable procedures redefined using this macro. * module/rnrs/arithmetic/fixnums.scm: Alias all predicates to their non-fixnum counterparts.
2011-01-30Add two new sets of fast quotient and remainder operatorsMark H Weaver2-37/+17
* libguile/numbers.c (scm_euclidean_quo_and_rem, scm_euclidean_quotient, scm_euclidean_remainder, scm_centered_quo_and_rem, scm_centered_quotient, scm_centered_remainder): New extensible procedures `euclidean/', `euclidean-quotient', `euclidean-remainder', `centered/', `centered-quotient', `centered-remainder'. * libguile/numbers.h: Add function prototypes. * module/rnrs/base.scm: Remove incorrect stub implementations of `div', `mod', `div-and-mod', `div0', `mod0', and `div0-and-mod0'. Instead do renaming imports of `euclidean-quotient', `euclidean-remainder', `euclidean/', `centered-quotient', `centered-remainder', and `centered/', which are equivalent to the R6RS operators. * module/rnrs/arithmetic/fixnums.scm (fxdiv, fxmod, fxdiv-and-mod, fxdiv0, fxmod0, fxdiv0-and-mod0): Remove redundant checks for division by zero and unnecessary complexity. (fx+/carry): Remove unneeded calls to `inexact->exact'. * module/rnrs/arithmetic/flonums.scm (fldiv, flmod, fldiv-and-mod, fldiv0, flmod0, fldiv0-and-mod0): Remove redundant checks for division by zero and unnecessary complexity. Remove unneeded calls to `inexact->exact' and `exact->inexact' * test-suite/tests/numbers.test: (test-eqv?): New internal predicate for comparing numerical outputs with expected values. Add extensive test code for `euclidean/', `euclidean-quotient', `euclidean-remainder', `centered/', `centered-quotient', `centered-remainder'. * test-suite/tests/r6rs-arithmetic-fixnums.test: Fix some broken test cases, and remove `unresolved' test markers for `fxdiv', `fxmod', `fxdiv-and-mod', `fxdiv0', `fxmod0', and `fxdiv0-and-mod0'. * test-suite/tests/r6rs-arithmetic-flonums.test: Remove `unresolved' test markers for `fldiv', `flmod', `fldiv-and-mod', `fldiv0', `flmod0', and `fldiv0-and-mod0'. * doc/ref/api-data.texi (Arithmetic): Document `euclidean/', `euclidean-quotient', `euclidean-remainder', `centered/', `centered-quotient', and `centered-remainder'. (Operations on Integer Values): Add cross-references to `euclidean/' et al, from `quotient', `remainder', and `modulo'. * doc/ref/r6rs.texi (rnrs base): Improve documentation for `div', `mod', `div-and-mod', `div0', `mod0', and `div0-and-mod0'. Add cross-references to `euclidean/' et al. * NEWS: Add NEWS entry.
2010-08-28Several fixes to R6RS librariesAndreas Rottmann1-1/+1
* module/rnrs/arithmetic/fixnums.scm (fixnum-width): Make this return an an exact integer instead of an inexact number. * module/rnrs/base.scm (assertion-violation): Implement. * module/rnrs/conditions.scm (simple-conditions): Allow also simple conditions as argument. * module/rnrs/enums.scm (define-enumeration): Properly construct empty enumeration sets. * module/rnrs/exceptions.scm (guard): Don't restrict the body to a single expression. * module/rnrs/records/syntactic.scm (define-record-type0): Expand into a series of definitions only.
2010-06-16remove encoding of versions into the file system (for now?)Andy Wingo3-0/+0
* module/ice-9/boot-9.scm (find-versioned-module): Remove. Still had some bugs (e.g. for "." in the path and in finding compiled files), did too much computation and statting, and we don't really want to promote versioning. Nor do we want to hard-code a particular encoding of versions in the file-system. Perhaps the real way to do this is to be extensible somehow. (try-module-autoload): Just dispatch to primitive-load-path in all cases. * module/rnrs * module/rnrs.scm: * module/rnrs/arithmetic/bitwise.scm: * module/rnrs/arithmetic/fixnums.scm: * module/rnrs/arithmetic/flonums.scm: * module/rnrs/base.scm: * module/rnrs/conditions.scm: * module/rnrs/control.scm: * module/rnrs/enums.scm: * module/rnrs/eval.scm: * module/rnrs/exceptions.scm: * module/rnrs/files.scm: * module/rnrs/hashtables.scm: * module/rnrs/io/simple.scm: * module/rnrs/lists.scm: * module/rnrs/mutable-pairs.scm: * module/rnrs/mutable-strings.scm: * module/rnrs/programs.scm: * module/rnrs/r5rs.scm: * module/rnrs/records/inspection.scm: * module/rnrs/records/procedural.scm: * module/rnrs/records/syntactic.scm: * module/rnrs/sorting.scm: * module/rnrs/syntax-case.scm: * module/rnrs/unicode.scm: Move these files, eliding the "6/" infix, so that they are in the normal (unversioned) module path.
2010-05-20Test suite and fixes for R6RS (rnrs arithmetic fixnums).Julian Graham1-44/+57
* module/rnrs/arithmetic/6/fixnums.scm: Fix missing imports; (fixnum-width, greatest-fixnum, least-fixnum): Redefine these as zero-argument procedures; Fix argument mismatches in several functions. * test-suite/Makefile.am: Add tests/r6rs-arithmetic-fixnums.test to SCM_TESTS. * test-suite/tests/r6rs-arithmetic-fixnums.test: New file.
2010-05-20Implementation and test cases for the R6RS (rnrs arithmetic flonums)Julian Graham2-0/+471
library. * module/Makefile.am: Add rnrs/arithmetic/6/fixnums.scm and rnrs/arithmetic/6/flonums.scm to RNRS_SOURCES. * module/rnrs/6/base.scm: (div-and-mod, div0, mod0, div0-and-mod0): New functions; this `div' implementation is not quite right, but we'll come back to it later. * module/rnrs/arithmetic/6/fixnums.scm: New file. * module/rnrs/arithmetic/6/flonums.scm: New file. * test-suite/Makefile.am: Add tests/r6rs-arithmetic-flonums.test to SCM_TESTS. * test-suite/tests/r6rs-arithmetic-flonums.test: New file.
2010-05-20Fix missing imports for `(rnrs arithmetic bitwise)'.Julian Graham1-1/+3
* module/Makefile.am: Add module/rnrs/arithmetic/6/bitwise.scm to RNRS_SOURCES. * module/rnrs/arithmetic/6/bitwise.scm: Import `(rnrs control)' and `modulo' from `(guile)'. * test-suite/Makefile.am: Add r6rs-arithmetic-bitwise.test to SCM_TESTS.
2010-05-20Implementation and test cases for the R6RS (rnrs arithmetic bitwise)Julian Graham1-0/+123
library. * module/rnrs/arithmetic/6/bitwise.scm: New file. * test-suite/tests/r6rs-arithmetic-bitwise.test: New file.