Skip to content
Related Articles

Related Articles

Numbers in LISP

View Discussion
Improve Article
Save Article
  • Last Updated : 08 Aug, 2022

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:

  • floor:  floor returns the nearest smallest number.
  • ceiling: ceiling return the nearest largest number.
  • round: rounds the argument or quotient of the arguments to the nearest integer.
  • mod: Returns the remainder in a division operation.
  • complex:  Returns a number whose real part is real part and whose imaginary part is imaginary part

Attributes Used:

  • setq: It is used to set the value to a variable.
  • printc: It is used for print output.
  • terpri: It is used to produce a new line. 
  • write: It is used for writing.

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 "substration")
(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))



Example 2:


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



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!