This is the way I would approach the problem.
;; returns largest index >=
;; else return nil
(defun >=index (nu idx1 idx2)
(if (>= nu (max idx1 idx2)) (max idx1 idx2)))
;; if between returns the idx closest to
;; else return nil
(defun >< (nu idx1 idx2)
(if (and (> nu (min idx1 idx2)) (< nu (max idx1 idx2)))
(if (> (- idx1 nu) (- idx2 nu)) idx2 idx1)))
;; if between or = max returns the idx closest to
;; else return nil
(defun ><=Max (nu idx1 idx2)
(if (and (> nu (min idx1 idx2)) (<= nu (max idx1 idx2)))
(if (> (abs(- idx1 nu)) (abs(- idx2 nu))) idx2 idx1)))
;; if between or = min returns the idx closest to
;; else return nil
(defun ><=Min (nu idx1 idx2)
(if (and (>= nu (min idx1 idx2)) (< nu (max idx1 idx2)))
(if (> (abs(- idx1 nu)) (abs(- idx2 nu))) idx2 idx1)))
(defun diff (nu idx)
(abs (- nu idx)))
(defun c:test()
(print "=============")
(Print (>< 30 12 54))
(Print (>< 10 12 54))
(print "=============")
(Print (><=max 30 12 54))
(Print (><=max 54 12 54))
(Print (><=max 55 12 54))
(Print (><=max 12 12 54))
(print "=============")
(Print (><=min 30 12 54))
(Print (><=min 54 12 54))
(Print (><=min 11 12 54))
(Print (><=min 12 12 54))
(print "=============")
)