浮点数对象
**********

type PyFloatObject

   这个 "PyObject" 的子类型代表一个 Python 浮点数对象。

PyTypeObject PyFloat_Type
    * 属于 稳定 ABI.*

   这个 "PyTypeObject" 实例代表 Python 浮点数类型。这与 Python 层面的
   "float" 是同一个对象。

int PyFloat_Check(PyObject *p)

   如果它的参数是一个 "PyFloatObject" 或者 "PyFloatObject" 的子类型则
   返回真值。 此函数总是会成功执行。

int PyFloat_CheckExact(PyObject *p)

   如果它的参数是一个 "PyFloatObject" 但不是 "PyFloatObject" 的子类型
   则返回真值。 此函数总是会成功执行。

PyObject *PyFloat_FromString(PyObject *str)
    *返回值：新的引用。** 属于 稳定 ABI.*

   根据字符串 *str* 的值创建一个 "PyFloatObject"，失败时返回 "NULL"。

PyObject *PyFloat_FromDouble(double v)
    *返回值：新的引用。** 属于 稳定 ABI.*

   根据 *v* 创建一个 "PyFloatObject" 对象，失败时返回 "NULL"。

double PyFloat_AsDouble(PyObject *pyfloat)
    * 属于 稳定 ABI.*

   返回 *pyfloat* 的内容的 C double 表示形式。如果 *pyfloat* 不是一个
   Python 浮点数对象但是具有 "__float__()" 方法，则会先调用此方法来将
   *pyfloat* 转换为浮点数。如果 "__float__()" 未定义则将回退至
   "__index__()"。此方法在失败时将返回 "-1.0"，因此开发者应当调用
   "PyErr_Occurred()" 来检测错误。

   在 3.8 版本发生变更: 如果可能将使用 "__index__()"。

double PyFloat_AS_DOUBLE(PyObject *pyfloat)

   返回 *pyfloat* 的 C double 表示形式，但不带错误检测。

PyObject *PyFloat_GetInfo(void)
    *返回值：新的引用。** 属于 稳定 ABI.*

   返回一个 structseq 实例，其中包含有关 float 的精度、最小值和最大值
   的信息。它是头文件 "float.h" 的一个简单包装。

double PyFloat_GetMax()
    * 属于 稳定 ABI.*

   返回 C double 形式的最大可表示有限浮点数 *DBL_MAX*。

double PyFloat_GetMin()
    * 属于 稳定 ABI.*

   返回 C double 形式的最小正规化正浮点数 *DBL_MIN*。

Py_INFINITY

   这个宏会扩展为一个 double 类型的常量表达式，它代表正无穷大。

   这等价于 C11 标准 "<math.h>" 头文件中的 "INFINITY" 宏。

   自 3.15 版起已处于 Soft deprecated 状态.

Py_NAN

   这个宏会扩展为一个 double 类型的常量表达式，它代表一个 quiet
   not-a-number (qNaN) 值。

   在大多数平台上，这等价于 C11 标准 "<math.h>" 头文件中的 "NAN" 宏。

Py_HUGE_VAL

   等价于 "INFINITY"。

   自 3.14 版起已处于 Soft deprecated 状态.

Py_MATH_E

   "math.e" 常量的定义（基于 double 类型的精度）。

Py_MATH_El

   高精度 (long double) 的 "e" 常量定义。

   从 3.15 版起已弃用，将在 3.20 版中移除.

Py_MATH_PI

   "math.pi" 常量的定义（基于 double 类型的精度）。

Py_MATH_PIl

   高精度 (long double) 的 "pi" 常量定义。

   从 3.15 版起已弃用，将在 3.20 版中移除.

Py_MATH_TAU

   "math.tau" 常量的定义（基于 double 类型的精度）。

   Added in version 3.6.

Py_RETURN_NAN

   从一个函数返回 "math.nan"。

   在大多数平台上，这等价于 "return PyFloat_FromDouble(NAN)"。

Py_RETURN_INF(sign)

   从一个函数返回 "math.inf" 或 "-math.inf"，具体取决于 *sign* 的符号
   值。

   在大多数平台上，这等价于以下代码:

      return PyFloat_FromDouble(copysign(INFINITY, sign));

Py_IS_FINITE(X)

   如果给定的浮点数 *X* 为有限值，即为规格数、非规格数或零，而不是无穷
   大或 NaN 则返回 "1"。否则返回 "0"。

   自 3.14 版起已处于 Soft deprecated 状态: 改用 "isfinite"。

Py_IS_INFINITY(X)

   如果给定的浮点数 *X* 为正或负无穷大则返回 "1"。否则返回 "0"。

   自 3.14 版起已处于 Soft deprecated 状态: 改用 "isinf"。

Py_IS_NAN(X)

   如果给定的浮点数 *X* 为非数字 (NaN) 值则返回 "1"。否则返回 "0"。

   自 3.14 版起已处于 Soft deprecated 状态: 改用 "isnan"。


打包与解包函数
==============

The pack and unpack functions provide an efficient platform-
independent way to store floating-point values as byte strings. The
Pack routines produce a bytes string from a C double, and the Unpack
routines produce a C double from such a bytes string. The suffix (2, 4
or 8) specifies the number of bytes in the bytes string:

* The 2-byte format is the IEEE 754 binary16 half-precision format.

* The 4-byte format is the IEEE 754 binary32 single-precision format.

* The 8-byte format is the IEEE 754 binary64 double-precision format.

The NaN type may not be preserved on some platforms while unpacking
(signaling NaNs become quiet NaNs), for example on x86 systems in
32-bit mode.

It's assumed that the double type has the IEEE 754 binary64 double
precision format.  What happens if it's not true is partly accidental
(alas). On non-IEEE platforms with more precision, or larger dynamic
range, than IEEE 754 supports, not all values can be packed; on non-
IEEE platforms with less precision, or smaller dynamic range, not all
values can be unpacked.  The packing of special numbers like INFs and
NaNs (if such things exist on the platform) may not be handled
correctly, and attempting to unpack a bytes string containing an IEEE
INF or NaN may raise an exception.

Added in version 3.11.


打包函数
--------

The pack routines write 2, 4 or 8 bytes, starting at *p*. *le* is an
int argument, non-zero if you want the bytes string in little-endian
format (exponent last, at "p+1", "p+3", or "p+6" and "p+7"), zero if
you want big-endian format (exponent first, at *p*). Use the
"PY_LITTLE_ENDIAN" constant to select the native endian: it is equal
to "0" on big endian processor, or "1" on little endian processor.

返回值：如果一切正常则为 "0"，如果出错则为 "-1" (并会设置一个异常，最
大可能为 "OverflowError")。

int PyFloat_Pack2(double x, char *p, int le)

   将 C double 打包为 IEEE 754 binary16 半精度格式。

int PyFloat_Pack4(double x, char *p, int le)

   将 C double 打包为 IEEE 754 binary32 单精度格式。

int PyFloat_Pack8(double x, char *p, int le)

   将 C double 打包为 IEEE 754 binary64 双精度格式。

   **CPython 实现细节：** This function always succeeds in CPython.


解包函数
--------

The unpack routines read 2, 4 or 8 bytes, starting at *p*.  *le* is an
int argument, non-zero if the bytes string is in little-endian format
(exponent last, at "p+1", "p+3" or "p+6" and "p+7"), zero if big-
endian (exponent first, at *p*). Use the "PY_LITTLE_ENDIAN" constant
to select the native endian: it is equal to "0" on big endian
processor, or "1" on little endian processor.

返回值：解包后的 double。出错时，返回值为 "-1.0" 且 "PyErr_Occurred()"
为真值 (并且会设置一个异常，最大可能为 "OverflowError")。

**CPython 实现细节：** These functions always succeed in CPython.

double PyFloat_Unpack2(const char *p, int le)

   将 IEEE 754 binary16 半精度格式解包为 C double。

double PyFloat_Unpack4(const char *p, int le)

   将 IEEE 754 binary32 单精度格式解包为 C double。

double PyFloat_Unpack8(const char *p, int le)

   将 IEEE 754 binary64 双精度格式解包为 C double。
