Emacs Lisp: Arithmetic

By Xah Lee. Date: . Last updated: .

Addition

(+ 4 5 1) ; 10

Subtraction

(- 9 2) ; 7
(- 9 2 3) ; 4

Multiplication

(* 2 3) ; 6
(* 2 3 2) ; 12

Addition

;; integer part of quotient
(/ 7 2) ; 3

Division

(/ 7 2.0) ; 3.5

Mod, Remainder

(% 7 4) ; 3

Power; Exponential

(expt 2 3) ; 8

WARNING: single digit decimal number such as 2. needs a zero after the dot, like this: 2.0. For example, (/ 7 2.) returns 3, not 3.5.

;; 3. is a integer, 3.0 is a float
(integerp 3.) ;  t
(floatp 3.) ;  nil
(floatp 3.0) ;  t

Function names that end with a “p” often means it return either true or false. (The “p” stands for “predicate”) t means true; nil means false.

(info "(elisp) Numbers")

Lisp Basics

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Lisp Basics

Basics

Lisp Data Structure

Function

Lisp Symbol

Lisp Misc

Working with Elisp