# 3.4 数字比较

要测试数字是否相等，通常应该使用 = 比较, 而非使用非数字比较谓词，如 eq, eql 和 equal。浮点和大整数对象在数值意义上可以相等。如果你使用 eq 来比较它们，你是在测试它们是否是同一个对象；如果使用 eql 或 equal ，则是在测试它们的值是否不可区分。相反，= 是用于数字比较，有时会在非数字比较时返回 t ，反之亦然。请参阅浮动基础知识。

在 Emacs Lisp 中，如果两个 fixnum 在数值上相等，则它们是同一个 Lisp 对象。也就是说，比较 fixnum 时，eq 和 = 是等价的。有时使用 eq 将未知值与 fixnum 进行比较很方便，因为如果未知值不是数字，eq 并不会报告错误——它接受任何类型的参数。相比之下，如果参数不是数字或标记，那么 = 会抛出错误。但是，为了更好的编程实践，请尽量使用 = ，即便是比较整数。

使用 eql 或 equal 比较数字，则会将两个数字比较是否具有相同的数据类型（都是整数，或都是浮点数）和相同的值。相比之下， = 可以将整数和浮点数视为相等。请参阅相等谓词。

还有一个问题：因为浮点运算并不精确，所以检查浮点值的相等性通常是一个坏主意。通常最好使用近似相等测试。这里是一个执行此操作的函数：

(defvar fuzz-factor 1.0e-6) (defun approx-equal (x y) (or (= x y) (< (/ (abs (- x y)) (max (abs x) (abs y))) fuzz-factor)))

Function：= number-or-maker \&rest number-or-makers 此函数测试其所有参数在数值上是否相等，如果相等则返回 t，否则返回 nil。

Function：eql value1 value2 此函数的作用类似于 eq 不同的是，两个参数都因该是数字。它按类型和数值比较数字，因此 (eql 1.0 1)返回nil，但是(eql 1.0 1.0)和 (eql 1 1)都返回 t。这可用于比较大整数和小整数。

Function：/= number-or-marker1 number-or-marker2 此函数测试其参数在数值上是否相等，如果不相等 t，否则返回 nil。

Function：< number-or-maker \&rest number-or-makers 此函数测试每个参数是否严格小于下一个参数。如果是，则返回 t，否则返回 nil。

Function：<= number-or-maker \&rest number-or-makers 此函数测试每个参数是否小于或等于下一个参数。如果是，则返回 t，否则返回 nil。

Function：> number-or-maker \&rest number-or-makers 此函数测试每个参数是否严格大于下一个参数。如果是，则返回 t，否则返回 nil。

Function：>= number-or-maker \&rest number-or-makers 此函数测试每个参数是否大于或等于下一个参数。如果是，则返回 t，否则返回 nil。

Function：max number-or-maker \&rest numbers-or-makers 此函数返回最大的参数。

（最多 20 个） ⇒ 20 （最大 1 2.5） ⇒ 2.5 （最大 1 3 2.5） ⇒ 3 Function：min number-or-maker \&rest numbers-or-makers 此函数返回最小参数。

(最小 -4 1) ⇒ -4 Function：abs number 此函数返回number的绝对值。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emacs-lisp.ivory.cafe/shu-zi/shu-zi-bi-jiao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
