IntOperations

© 2012 John Abbott and Anna M. Bigatti
GNU Free Documentation License, Version 1.2



CoCoALib Documentation Index

User documentation

The class BigInt is intended to represent (signed) integers of practically unlimited range; it is currently based on the implementation in the GMP big integer library.

The class MachineInt is intended to help you write functions which accept arguments whose type is a machine integer offering a safe interface for signed and unsigned maching integers.

When the CoCoALib documentation says integer it means both big integers and machine integers which are mainly interchangable. Do remember, though, that operations between two machine integers are handled directly by C++, and problems of overflow can occur.

The few exceptions accepting only long are clearly indicated and usually apply to indices and subscripts.

Examples

Queries

Only for BigInt

Operations

Infix operators

  1. normal arithmetic (potentially inefficient because of temporaries)
  2. arithmetic and assignment
  3. arithmetic ordering
  4. increment/decrement

cmp

(three way comparison)

Sundry standard functions

(Several basic number theoretical operations are defined in NumTheory) Let n be an integer, let hi, lo be machine integers

These functions return BigInt

Conversion functions

Only for BigInt

Miscellany

Only for BigInt

Procedures for arithmetic

Assignment is always to leftmost argument(s) a, a BigInt. Second and/or third argument of type BigInt.

Error Conditions and Exceptions

Error conditions are signalled by exceptions. Examples of error conditions are impossible arithmetic operations such as division by zero, overly large arguments (e.g. second argument to binomial must fit into a machine long), and exhaustion of resources.

Currently the exception structure is very simplistic:

ERR::ArgTooBig value supplied is too large for the answer to be computed
ERR::BadArg unsuitable arg(s) supplied (or input number too large)
ERR::BadNumBase the base must be between 2 and 36
ERR::DivByZero division by zero
ERR::ExpTooBig exponent is too large
ERR::IntDivByNeg inexact integer division by a negative divisor
ERR::NegExp negative exponent
ERR::ZeroModulus the modulus specified is zero

Maintainer Documentation

Bugs, shortcomings and other ideas

The power functions should handle power(0,0) correctly; maybe they should also allow high powers of -1,0,1 (without complaining about the exponent being too big).

Only partial access to all the various division functions offered by the C interface to GMP. Many other GMP functions are not directly accessible.

IsExactIroot has rather a lot of signatures.

Main changes

2012