Integers

AutoCAD AutoLISP & Visual LISP

 
Integers
 
 
 

Integers are whole numbers that do not contain a decimal point. AutoLISP integers are 32-bit signed numbers with values ranging from +2,147,483,647 to -2,147,483,648. (Note, however, that the getint function only accepts 16-bit numbers ranging from +32767 to -32678.) When you explicitly use an integer in an AutoLISP expression, that value is known as a constant. Numbers such as 2, -56, and 1,200,196 are valid AutoLISP integers.

If you enter a number that is greater than the maximum integer allowed (resulting in integer overflow), AutoLISP converts the integer to a real number. However, if you perform an arithmetic operation on two valid integers, and the result is greater than the maximum allowable integer, the resulting number will be invalid. The following examples illustrate how AutoLISP handles integer overflow.

The largest positive integer value retains its specified value:

_$ 2147483647
2147483647

If you enter an integer that is greater than the largest allowable value, AutoLISP returns the value as a real:

_$ 2147483648 
2.14748e+009

An arithmetic operation involving two valid integers, but resulting in integer overflow, produces an invalid result:

_$ (+ 2147483646 3)
-2147483647

In this example the result is clearly invalid, as the addition of two positive numbers results in a negative number. But note how the following operation produces a valid result:

_$ (+ 2147483648 2)
2.14748e+009

In this instance, AutoLISP converts 2147483648 to a valid real before adding 2 to the number. The result is a valid real.

The largest negative integer value retains its specified value:

_$ -2147483647
-2147483647

If you enter a negative integer larger than the greatest allowable negative value, AutoLISP returns the value as a real:

_$ -2147483648
-2.14748e+009

The following operation concludes successfully, because AutoLISP first converts the overflow negative integer to a valid real:

_$ (- -2147483648 1)
-2.14748e+009