Next: , Previous: , Up: Types of Numbers   [Contents][Index]


63.2.2 The Type ‘bigq

The type ‘bigq’ is an abstract C type for arbitrary-precision rational numbers (fractions). The actual C type provided by the GMP-MPQ library is ‘mpq_t’.

Any other library which implements something similar to MPQ, should be accessed via the abstract type ‘bigq’, too.

Lisp objects can be tested for the type ‘bigq’ by the following predicates.

Function: bigqp object

This predicate tests whether its argument is a fraction of integers (as provided by GMP-MPQ), and returns t if so, nil otherwise.

Function: ratiop object

This is roughly the same as bigqp and is provided for compatibility to XEmacs.

Furthermore, for ‘bigq’ objects exist two accessor functions, namely numerator and denominator to access the respective parts of a fraction.

Function: numerator rational

Return the numerator of the canonical form of rational. If rational is an integer, rational is returned.

Function: denominator rational

Return the denominator of the canonical form of rational. If rational is an integer, 1 is returned.

The read syntax of rational quotients is the intuitive one, and identical to their output syntax if the quotients are not integral (i.e. have denominator 1). The lisp reader interprets ‘a/b’ with a a rational integer and b a positive integer as the quotient ‘a/b’.

Within the lisp reader quotients are automatically cancelled and stored in their canonical form (a coprime to b), consider the following examples:

1/3
     ⇒ 1/3
6/18
     ⇒ 1/3
21/3
     ⇒ 7

Please note that the result in the latter example is not of type ‘bigq’ because auto-coercion is in effect (see the notes in Category integer) which canonicalises rational fractions with denominator 1 to rational integers.

Also note that the read syntax for quotients steals a whole class of possible symbol identifiers. In a non-ENT-SXEmacs 1/3 is a valid name for a variable.

Beside the creation of rational quotients, the arithmetic operation // can also be used to construct quotients. This function is not exclusively a ‘bigq’-constructor, but passing two integral arguments (interpretable as numerator and denominator) will yield a quotient:

(// 2 3)
     ⇒ 2/3

Again, in spite of their name arbitrary-precision quotients do not offer a way to take influence on the precision or internal representation of ‘bigq’s (unlike the float types). The number of limbs used, read the precision, is administered solely by the underlying library implementation.


Next: , Previous: , Up: Types of Numbers   [Contents][Index]