XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

/


Type:   -   function (subr)
Source:   -   xlmath.c

Syntax

(/ expr ... )
expr - integer or floating point number/expression
returns - the result of the division

Description

The '/' function divides the first number given by the rest of the numbers and returns the result. If all the expressions are integers, the division is integer division. If any expression is a floating point number, then the division will be floating point division.

Examples

(/ 1)                                 ; returns 1
(/ 1 2)                               ; returns 0 (integer division)
(float (/ 1 2))                       ; returns 0 (integer division)
(/ (float 1) 2)                       ; returns 0.5
(/ 1 1.0 2)                           ; returns 0.5 (short cut)
(/ (float 1) 2 3)                     ; returns 0.166667
(/ 1 1.0 2 3 4)                       ; returns 0.0416667
(print (+ 1 2 (* 3.5 (/ 3.9 1.45))))  ; returns and prints 12.4138

Common Lisp: Common Lisp supports a ratio data type. This means that (/ 3 4 5) will result in the value 3/20. In XLISP (/ 3 4 5) will result in 0 [because of integer values]. (/ 3.0 4 5) will result in 0.15 for both XLISP and Common Lisp.

Note: An easy way to force a sequence of integers to be divided as floating point numbers is to insert the number 1.0 after the first argument in the list of arguments to the divider function.

See the  /  function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next