Function Definitions

1  -  Mathematics

+ ..... Adds

(+ 2 3)  returns 5
(+ 4 5.6 -2)  returns 7.6
After (setq a 20 b 9)
(+ a b)  returns 29


- ..... Subtracts

(- 9 7)  returns 2
(- 8 4 0.5)  returns 3.5
After (setq a 20 b 9)
(- a b)  returns 11
(- b a)  returns -11
(- a)  returns -20. When only one argument is supplied, its value is subtracted from 0, switching the sign of any number.


* ..... Multiplies

(* 6 7)  returns 42
(* 2 -3 1.5)  returns -9.0
After (setq a 3 b 4.5)
(* a b)  returns 13.5
(* a a)  returns 9


/ ..... Divides

(/ 12 6)  returns 2
(/ 11 6)  returns 1 (Division using only integers ignores any remainder.  Beware of "integer division.")
(/ 11 6.0)  returns 1.833333
(/ 12 3 2)  returns 2
(/ 12 -2.0)  returns -6.0


rem ..... Returns a remainder resulting from division

(rem 10 3)  returns 1
(rem 10 5)  returns 0
(rem 6.2 1.2)  returns 0.2


1+ ..... Increments by 1

(1+ 16)  returns 17
After (setq a 21)
(1+ a)  returns 22.  Used with setq, this serves as a loop counter for iteration. For example, (setq c (1+ c)).
(1+  -4)  returns -3


1- ..... Decrements by 1

(1- 16)  returns 15
After (setq a -8)
(1- a)  returns -9


abs ..... Returns the absolute of a number

(abs 7.0)  returns 7.0
(abs -6)  returns 6


fix ..... Discards fractional portion of a number and returns an integer

(fix 7. 1)  returns 7
(fix 7.9)  returns 7
(fix -4.6)  returns -4


float ..... Converts a number to a real number (floating point decimal number)

(float 5)  returns 5.0
(float 5.82)  returns 5.82


gcd ..... Returns the greatest factor (divisor) common to two or more integers.  Arguments must be positive integers.

(gcd 21 39)  returns 3
(gcd 102 138)  returns 6
(gcd 30 45 60)  returns 15

Autodesk says this function returns the "greatest common denominator" (a meaningless phrase).  It is better to think of it as "greatest common divisor." 


min ..... Returns the smallest (lowest) of two or more numbers

(min 8 3 11.88 14 6)  returns 3.0
(min 13 -28 2 66)  returns -28


max ..... Returns the greatest of two or more numbers

(max 8 3 11.88 14 6)  returns 14.0
(max -22 -2 16)  returns 16


sqrt ..... Returns the square root of a number as a real

(sqrt 16)  returns 4.0
(sqrt 2.0)  returns 1.414214


expt ..... Raises a given number to a given power

(expt 3 4)  returns 81
(expt 2.0 5.0)  returns 32
(expt 3 -2)  returns 0 (negative exponents applied to integers can appear to give incorrect results because of integer division)
(expt 3.0 -2.0)  returns 0.111111
(expt 256 0.25)  returns 4.0
After (setq a 2.25 b 0.5)
(expt a b)  returns 1.5


exp ..... Returns e raised to a given power

(exp 1.0)  returns 2.71828
(exp 2.14)  returns 8.49944
(exp 0.4)  returns 1.49182
(exp -2.0)  returns 0.135335

Euler's number, e, is the base of natural logarithms, and equals approximately 2.71828.  It is used to simplify certain formulas in calculus.  Compare log below.


log ..... Returns the natural log (base e) of a number.  Compare exp above.

(log 3)  returns 1.09861
(log 1.82)  returns 0.598837
(log 0.25)  returns -1.38629


cvunit ..... Converts a value, or a list of values, from one unit to another.  The first argument is the number to be converted, the second argument is the unit from which you are converting, the third argument is the unit to which you are converting.

(cvunit 10 "inch" "mm")  returns 254.0
(cvunit 100 "mm" "inch")  returns 3.93701
(cvunit 25 "lb" "kg")  returns 11.3398
(cvunit (list 6 5 24) "inch" "feet")  returns (0.5  0.416667  2.0)
After (setq a 1 b 2)
(cvunit a "inch" "mm")  returns 25.4
(cvunit (list (eval a) (eval b)) "inch" "mm")  returns (25.4 50.8)

The unit names for the second and third arguments must be spelled as they appear in the ACAD.UNT file.  The cvunit function depends on the values in ACAD.UNT.  Therefore, for most conversions, simple multiplication or division by the appropriate factor within the AutoLISP expression is preferred over dependence on an external file.



 
HOME

Copyright © 1988, 1998 Ronald W. Leigh