Next: , Up: Numbers   [Contents][Index]

5.4.1 Types of Numbers

First understand that librep distinguishes exact and inexact numbers. This is similar to Scheme. Quoting from the Scheme standard:

… numbers are either exact or inexact. A number is exact if it was written as an exact constant or was derived from exact numbers using only exact operations. A number is inexact if it was written as an inexact constant, if it was derived using inexact ingredients, or if it was derived using inexact operations. Thus inexactness is a contagious property of a number.

Librep has three types of numbers: integer, rational, and float.

With gmp, exact numbers include both integers and rational numbers. There is no theoretical limit to the range of the values that may be represented 3.

Without gmp, only integer is exact. Rational numbers get approximated with float. On 32-bit system, integer is signed 30-bit (not 32 bits), and 62-bit on 64-bit system.4

Inexact numbers are currently implemented using double precision floating point values.

When exact arguments are passed to functions which take float arguments, then they are automatically converted to float.

Note that Rep often handles integer overflow by converting the result from integer to float.



However, depending on implementation restrictions, very large integers may be coerced to an inexact representation.


Internally, unsigned 64-bit integer is supported too, and used in some cases. But this is not available to Lisp programmers.