Open In App

Numbers in LISP

LISP is a list processing programming language. It is widely used in the manipulation of data strings. It provides an input and output library. LISP provides a macro system and provides well control structures for the manipulation of data.

LISP Math Function:

Attributes Used:

Example 1:






; Normal Arithmetic calculation in
; LISP(Addition, Subtraction, Multiplication, division)
;set value 1 to 190
; set value 2 to 78
(setq val1 190)
(setq val2 78)
   
;addition operation
(princ "addition")
(print (+ val1 val2))
 
;subtraction operation
(princ "subtraction")
(print (- val1 val2))
  
;multiplication operation
(princ "multiplication")
(print (* val1 val2))
 
;division operation
(princ "division")
(print (/ val1 val2))
 
;modulus operation
(princ "modulus")
(print (MOD val1 val2))
 
;increment a by 10
(princ "increment by 10")
(print (incf val1 val2))
 
;decrement b by 20
(princ "increment by 20")
(print (decf val1 val2))

Output:

 

Example 2:






;Predefined Arithmetic data type in LISP
(princ "floor:  ")
(write (floor 45.78))
(terpri)
 
(princ "ceiling:   ")
(write (ceiling 34.34))
(terpri)
 
(princ "round:   ")
(write (round 34.3))
(terpri)
 
(princ "ffloor:   ")
(write (ffloor 34.43))
(terpri)
 
(princ "fceiling:   ")
(write (fceiling 34.12))
(terpri)
 
(princ "fround:   ")
(write (fround 34.75))
(terpri)
 
(princ "mod:   ")
(write (mod 34 5))
(terpri)
 
(princ "complex:   ")
(setq c (complex 6 7))
(write c)
(terpri)

Output:

 


Article Tags :