neg
methodThe neg
method is a number test method used to test if a number is less than zero. It only accepts one numeric parameter. The neg
method returns true for inputs less than zero and false for inputs greater than or equal to zero. The code line below shows the syntax for the neg
method.
(neg? number)
The neg
function is particularly useful when the user wishes to confirm if their calculations did not yield a negative value. It can promptly confirm if a number variable stores a value that is less than zero.
(ns clojure.examples.hello(:gen-class))(defn negg [](def x (neg? 0))(println x)(def x (neg? -1))(println x)(def x (neg? 9))(println x))(negg)
negg
.0
to the neg
method.Notice that
neg
returns false for the input0
since 0 is non-negative.
-1
to the neg
method.-1
to the neg
method is true.9
to the neg
method.9
to neg
is false.negg
defined in lines 4–12.