Float ('Nan') nghĩa là gì trong Python?

Cách đây không lâu, chúng tôi thậm chí đã cải thiện tài liệu để đề xuất người dùng sử dụng

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
31 thay vì
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
32 hoặc
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
33 khi họ muốn kiểm tra xem một số có phải là NaN hay không

Chúng ta có thể xem xét vấn đề này từ C và Python

Trong C, chúng ta có thể lấy bất kỳ NaN nào từ hàm

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
34

NaN trong C
#include 
#include 
#include 
#include 
#include 

int main[void] { 
	double f1 = nan["1"];
    uint64_t f1n; memcpy[&f1n, &f1, sizeof f1];
    printf["nan[\"1\"]   = %f [%" PRIx64 "]\n", f1, f1n];
 
    double f2 = nan["2"];
    uint64_t f2n; memcpy[&f2n, &f2, sizeof f2];
    printf["nan[\"2\"]   = %f [%" PRIx64 "]\n", f2, f2n];
 
    double f3 = -nan[""];
    uint64_t f3n; memcpy[&f3n, &f3, sizeof f3];
    printf["-nan[\"\"] = %f [%" PRIx64 "]\n", f3, f3n];
    
    double f4 = nan[""];
    uint64_t f4n; memcpy[&f4n, &f4, sizeof f4];
    printf["nan[\"\"]   = %f [%" PRIx64 "]\n", f4, f4n];
	return 0;
}

/**
 * Output:
 * nan["1"]   = nan [7ff8000000000001]
 * nan["2"]   = nan [7ff8000000000002]
 * -nan[""] = -nan [fff8000000000000]
 * nan[""]   = nan [7ff8000000000000]
 */

Nhưng trong Python thì không có sự tự do như vậy, chúng ta chỉ có thể lấy NaN thông qua hàm

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
35,
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
36 hoặc một số thao tác đặc biệt [chẳng hạn như
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37]. Giá trị trả về của
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
35 là một đối tượng Python, chúng ta nên tập trung vào triển khai cơ bản của nó. Tôi đặt một số mã ở đây để minh họa giá trị của NaN trong Python

NaN trong Python
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif

Như chúng ta có thể thấy, giá trị thực của

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
35 có thể thu được bằng macro
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
2, một giá trị cố định. Vì vậy, việc tạo NaN thành một singleton trong CPython là có sẵn

Có thể có chỗ nào chưa hoàn thiện mong bạn sửa lại.

Có 9007199254740990 NAN có thể có trong các float IEEE-754 64 bit

Nếu số float của bạn đến từ một nguồn dữ liệu bên ngoài hoặc một hàm được viết bằng C, Fortran, Java, Rust, v.v., thì bạn có thể nhận được bất kỳ một trong số 9e15 NAN đó. Sử dụng

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
32 để kiểm tra NAN không bao giờ đúng. Ngay cả khi chúng tôi đã lưu vào bộ đệm float['nan'] để điều này luôn đúng

math.nan is float['nan']

vẫn sẽ sai khi kiểm tra NAN bằng cách sử dụng

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
32

CPython hiện tại thậm chí không có bộ đệm 0. 0, vậy lợi ích của việc lưu trữ NAN vào bộ nhớ đệm là gì, vốn có khả năng hiếm hơn nhiều? . ]

Trong mọi trường hợp, bộ nhớ đệm của int và float là một chi tiết triển khai. Bạn không bao giờ nên dựa vào ints hoặc float để được lưu vào bộ đệm. Làm điều đó có nghĩa là bạn không còn viết mã Python độc lập với nền tảng nữa mà buộc mã của bạn vào một phiên bản cụ thể của một trình thông dịch cụ thể trên một hệ điều hành cụ thể

Các chức năng này không thể được sử dụng với các số phức tạp; . Sự khác biệt giữa các hàm hỗ trợ số phức và các hàm không hỗ trợ được tạo ra vì hầu hết người dùng không muốn học toán nhiều như yêu cầu để hiểu số phức. Nhận một ngoại lệ thay vì một kết quả phức tạp cho phép phát hiện sớm hơn số phức không mong muốn được sử dụng làm tham số, để lập trình viên có thể xác định cách thức và lý do tại sao nó được tạo ra ngay từ đầu

Các chức năng sau đây được cung cấp bởi mô-đun này. Trừ khi có ghi chú rõ ràng khác, tất cả các giá trị trả về đều là số float

Lý thuyết số và hàm biểu diễn¶

toán học. trần[x]

Trả về trần của x, số nguyên nhỏ nhất lớn hơn hoặc bằng x. Nếu x không phải là số float, hãy ủy quyền cho

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
43, giá trị này sẽ trả về giá trị
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
44

toán học. lược[n , k]

Trả về số cách chọn k mục từ n mục mà không lặp lại và không có thứ tự

Đánh giá thành

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
45 khi
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
0 và đánh giá bằng 0 khi
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
1

Còn được gọi là hệ số nhị thức vì nó tương đương với hệ số của số hạng thứ k trong khai triển đa thức của

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
2

Tăng

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
3 nếu một trong hai đối số không phải là số nguyên. Tăng
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4 nếu một trong hai đối số là phủ định

Mới trong phiên bản 3. 8

toán học. copysign[x , y]

Trả về một số float có độ lớn [giá trị tuyệt đối] của x nhưng dấu của y. Trên các nền tảng hỗ trợ số 0 có dấu,

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
5 trả về -1. 0

toán học. fabs[x]

Trả về giá trị tuyệt đối của x

toán học. giai thừa[n]

Trả về n giai thừa dưới dạng số nguyên. Tăng

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4 nếu n không nguyên hoặc âm

Không dùng nữa kể từ phiên bản 3. 9. Việc chấp nhận số float có giá trị nguyên [như

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
7] không được chấp nhận.

toán học. sàn[x]

Trả về sàn của x, số nguyên lớn nhất nhỏ hơn hoặc bằng x. Nếu x không phải là số float, hãy ủy quyền cho

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
8, giá trị này sẽ trả về giá trị
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
44

toán học. fmod[x , y]

Trả lại

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
30, như được xác định bởi thư viện nền tảng C. Lưu ý rằng biểu thức Python
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
31 có thể không trả về kết quả tương tự. Mục đích của tiêu chuẩn C là
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
30 chính xác [về mặt toán học; với độ chính xác vô hạn] bằng với
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
33 đối với một số nguyên n sao cho kết quả có cùng dấu với x và độ lớn nhỏ hơn
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
34. Thay vào đó,
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
31 của Python trả về kết quả có dấu y và có thể không tính toán được chính xác cho các đối số float. Ví dụ:
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
36 là
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37, nhưng kết quả của
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
38 của Python là
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
39, không thể biểu diễn chính xác dưới dạng số float và làm tròn thành số đáng ngạc nhiên là
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
30. Vì lý do này, hàm
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
31 thường được ưu tiên khi làm việc với số float, trong khi hàm
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
31 của Python được ưu tiên khi làm việc với số nguyên

toán học. frexp[x]

Trả về phần định trị và số mũ của x dưới dạng cặp

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
33. m là số float và e là số nguyên sao cho chính xác là
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
34. Nếu x bằng không, trả về ________ 235, nếu không thì ________ 236. Điều này được sử dụng để "chọn ra" đại diện bên trong của một float theo cách di động

toán học. fsum[có thể lặp lại]

Trả về một tổng giá trị dấu phẩy động chính xác trong iterable. Tránh mất độ chính xác bằng cách theo dõi nhiều tổng từng phần trung gian

math.nan is float['nan']
0

Độ chính xác của thuật toán phụ thuộc vào đảm bảo số học IEEE-754 và trường hợp điển hình khi chế độ làm tròn là chẵn một nửa. Trên một số bản dựng không phải của Windows, thư viện C cơ bản sử dụng phép cộng độ chính xác mở rộng và đôi khi có thể làm tròn hai lần một tổng trung gian khiến nó bị tắt ở bit ít quan trọng nhất

Để thảo luận thêm và hai cách tiếp cận thay thế, hãy xem công thức nấu ăn ASPN để biết tổng kết dấu phẩy động chính xác

toán học. gcd[*số nguyên]

Trả về ước số chung lớn nhất của các đối số nguyên đã chỉ định. Nếu bất kỳ đối số nào khác không, thì giá trị trả về là số nguyên dương lớn nhất là ước của tất cả các đối số. Nếu tất cả các đối số bằng 0, thì giá trị trả về là

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37.
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
38 không có đối số trả về
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37

Mới trong phiên bản 3. 5

Đã thay đổi trong phiên bản 3. 9. Đã thêm hỗ trợ cho số lượng đối số tùy ý. Trước đây, chỉ có hai đối số được hỗ trợ.

toán học. tiết lộ[a , b . 0, *, rel_tol=1e-09, abs_tol=0.0]

Trả về

math.nan is float['nan']
40 nếu giá trị a và b gần nhau và ngược lại là
math.nan is float['nan']
41

Việc hai giá trị có được coi là gần hay không được xác định theo dung sai tuyệt đối và tương đối đã cho

rel_tol là dung sai tương đối – đó là chênh lệch tối đa được phép giữa a và b, so với giá trị tuyệt đối lớn hơn của a hoặc b. Ví dụ: để đặt dung sai là 5%, hãy vượt qua

math.nan is float['nan']
42. Dung sai mặc định là
math.nan is float['nan']
43, đảm bảo rằng hai giá trị giống nhau trong khoảng 9 chữ số thập phân. rel_tol phải lớn hơn 0

abs_tol là dung sai tuyệt đối tối thiểu – hữu ích khi so sánh gần bằng không. abs_tol ít nhất phải bằng 0

Nếu không có lỗi xảy ra, kết quả sẽ là.

math.nan is float['nan']
44

Các giá trị đặc biệt của IEEE 754 của

math.nan is float['nan']
45,
math.nan is float['nan']
46 và
math.nan is float['nan']
47 sẽ được xử lý theo quy tắc của IEEE. Cụ thể,
math.nan is float['nan']
45 không được coi là gần với bất kỳ giá trị nào khác, kể cả
math.nan is float['nan']
45.
math.nan is float['nan']
46 và
math.nan is float['nan']
47 chỉ được coi là thân thiết với nhau

Mới trong phiên bản 3. 5

Xem thêm

PEP 485 – Hàm kiểm tra đẳng thức gần đúng

toán học. là hữu hạn[x]

Trả về

math.nan is float['nan']
40 nếu x không phải là vô cực cũng không phải là NaN và
math.nan is float['nan']
41 nếu ngược lại. [Lưu ý rằng
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
474 được coi là hữu hạn. ]

Mới trong phiên bản 3. 2

toán học. isinf[x]

Trả về

math.nan is float['nan']
40 nếu x là vô cực dương hoặc âm và ngược lại là
math.nan is float['nan']
41

toán học. isnan[x]

Trả về

math.nan is float['nan']
40 nếu x là NaN [không phải số] và ngược lại là
math.nan is float['nan']
41

toán học. isqrt[n]

Trả về căn bậc hai số nguyên của số nguyên n không âm. Đây là sàn của căn bậc hai chính xác của n, hoặc tương đương với số nguyên lớn nhất a sao cho a² ≤ n

Đối với một số ứng dụng, sẽ thuận tiện hơn nếu có số nguyên a nhỏ nhất sao cho n ≤ a², hay nói cách khác là giá trị trần của căn bậc hai chính xác của n. Đối với tích cực và, điều này có thể được tính bằng cách sử dụng _____ 1479

Mới trong phiên bản 3. 8

toán học. lcm[*số nguyên]

Trả về bội số chung nhỏ nhất của các đối số nguyên đã chỉ định. Nếu tất cả các đối số khác không, thì giá trị trả về là số nguyên dương nhỏ nhất là bội số của tất cả các đối số. Nếu bất kỳ đối số nào bằng 0, thì giá trị trả về là

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37.
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
421 không có đối số trả về
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
422

Mới trong phiên bản 3. 9

toán học. ldexp[x , i]

Trả lại

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
423. Đây thực chất là nghịch đảo của hàm
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
424

toán học. modf[x]

Trả về phần phân số và phần nguyên của x. Cả hai kết quả đều mang dấu của x và là số float

toán học. tiếp theo[x , y]

Trả về giá trị dấu phẩy động tiếp theo sau x về phía y

Nếu x bằng y, trả về y

ví dụ

  • // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    425 đi lên. hướng tới dương vô cực

  • // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    426 đi xuống. về phía âm vô cực

  • // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    427 tiến về 0

  • // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    428 đi xa từ con số không

Xem thêm

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
429

Mới trong phiên bản 3. 9

toán học. uốn[n , k=None]

Trả về số cách chọn k mục từ n mục mà không lặp lại và theo thứ tự

Đánh giá thành

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
430 khi
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
0 và đánh giá bằng 0 khi
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
1

Nếu k không được chỉ định hoặc là Không, thì k mặc định là n và hàm trả về

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
433

Tăng

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
3 nếu một trong hai đối số không phải là số nguyên. Tăng
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4 nếu một trong hai đối số là phủ định

Mới trong phiên bản 3. 8

toán học. sản phẩm[có thể lặp lại , *, start=1]

Tính tích của tất cả các phần tử trong lần lặp đầu vào. Giá trị bắt đầu mặc định cho sản phẩm là

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
422

Khi iterable trống, hãy trả về giá trị bắt đầu. Hàm này được dành riêng để sử dụng với các giá trị số và có thể từ chối các loại không phải là số

Mới trong phiên bản 3. 8

toán học. số dư[x , y]

Trả về phần còn lại kiểu IEEE 754 của x đối với y. Đối với x hữu hạn và y khác 0 hữu hạn, đây là hiệu của

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
33, trong đó
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
438 là số nguyên gần nhất với giá trị chính xác của thương số
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
439. Nếu
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
439 nằm chính xác ở giữa hai số nguyên liên tiếp, thì số nguyên chẵn gần nhất được sử dụng cho
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
438. Do đó, phần còn lại của
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
442 luôn thỏa mãn
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
443

Các trường hợp đặc biệt tuân theo IEEE 754. đặc biệt,

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
444 là x cho bất kỳ x hữu hạn nào và ________ 1445 n ________ 1446 nâng cao ________ 44 cho bất kỳ x không phải NaN nào. Nếu kết quả của phép toán còn lại bằng 0, thì số 0 đó sẽ có cùng dấu với x

Trên các nền tảng sử dụng dấu phẩy động nhị phân IEEE 754, kết quả của thao tác này luôn có thể biểu diễn chính xác. không có lỗi làm tròn được giới thiệu

Mới trong phiên bản 3. 7

toán học. trunc[x]

Trả về x đã loại bỏ phần phân số, để lại phần nguyên. Điều này làm tròn về 0.

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
448 tương đương với
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
449 đối với x dương và tương đương với
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
450 đối với x âm. Nếu x không phải là số float, hãy ủy quyền cho
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
451, giá trị này sẽ trả về giá trị
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
44

toán học. ulp[x]

Trả về giá trị của bit ít quan trọng nhất của float x

  • Nếu x là NaN [không phải số], trả về x

  • Nếu x là số âm, trả về

    // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    453

  • Nếu x là một số dương vô cực, trả về x

  • Nếu x bằng 0, hãy trả về số float có thể biểu diễn không chuẩn hóa dương nhỏ nhất [nhỏ hơn số float chuẩn hóa dương tối thiểu,

    // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    454]

  • Nếu x bằng số float dương lớn nhất có thể biểu diễn, hãy trả về giá trị của bit có nghĩa nhỏ nhất của x, sao cho số float đầu tiên nhỏ hơn x là

    // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    455

  • Mặt khác [x là một số hữu hạn dương], trả về giá trị của bit có nghĩa nhỏ nhất của x, sao cho số float đầu tiên lớn hơn x là

    // float['nan'] will call this function to get the value of float object.
    double
    _Py_parse_inf_or_nan[const char *p, char **endptr]
    {
        ...
        else if [case_insensitive_match[s, "nan"]] {
            s += 3;
            retval = negate ? -Py_NAN : Py_NAN;
        }
        ...
        return retval;
    }
    
    // Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
    #if !defined[Py_NAN]
    #  if _Py__has_builtin[__builtin_nan]
         // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
    #    define Py_NAN [__builtin_nan[""]]
    #else
         // Use C99 NAN constant: quiet Not-A-Number.
         // NAN is a float, Py_NAN is a double: cast to double.
    #    define Py_NAN [[double]NAN]
    #  endif
    #endif
    
    456

ULP là viết tắt của Đơn vị ở vị trí cuối cùng

Xem thêm

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
457 và
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
458

Mới trong phiên bản 3. 9

Lưu ý rằng

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
424 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
00 có kiểu gọi/trả lại khác với mẫu C tương đương của chúng. chúng lấy một đối số duy nhất và trả về một cặp giá trị, thay vì trả về giá trị trả về thứ hai của chúng thông qua một 'tham số đầu ra' [không có thứ như vậy trong Python]

Đối với các hàm

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
450,
// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
449 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
00, hãy lưu ý rằng tất cả các số dấu phẩy động có độ lớn đủ lớn đều là số nguyên chính xác. Các float của Python thường mang độ chính xác không quá 53 bit [giống như loại kép của nền tảng C], trong trường hợp đó, bất kỳ float x nào có
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
04 nhất thiết không có bit phân số

Hàm lũy thừa và logarit¶

toán học. cbrt[x]

Trả về căn bậc ba của x

Mới trong phiên bản 3. 11

toán học. exp[x]

Trả về e lũy thừa x, trong đó e = 2. 718281… là cơ số của logarit tự nhiên. Điều này thường chính xác hơn

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
05 hoặc
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
06

toán học. exp2[x]

Trả về 2 lũy thừa x

Mới trong phiên bản 3. 11

toán học. expm1[x]

Trả về e lũy thừa x, trừ 1. Ở đây e là cơ số của logarit tự nhiên. Đối với số float x nhỏ, phép trừ trong

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
07 có thể dẫn đến mất độ chính xác đáng kể;

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05

Mới trong phiên bản 3. 2

toán học. log[x[ , base]]

Với một đối số, trả về logarit tự nhiên của x [cơ số e]

Với hai đối số, trả lại logarit của x cho cơ số đã cho, được tính là

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
09

toán học. log1p[x]

Trả về logarit tự nhiên của 1+x [cơ số e]. Kết quả được tính theo cách chính xác cho x gần bằng không

toán học. log2[x]

Trả về logarit cơ số 2 của x. Điều này thường chính xác hơn

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
10

Mới trong phiên bản 3. 3

Xem thêm

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
11 trả về số bit cần thiết để biểu diễn một số nguyên ở dạng nhị phân, không bao gồm dấu và các số 0 ở đầu

toán học. log10[x]

Trả về logarit cơ số 10 của x. Điều này thường chính xác hơn

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
12

toán học. pow[x , y]

Return

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
13 nâng lên lũy thừa
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
14. Các trường hợp ngoại lệ tuân theo tiêu chuẩn IEEE 754 càng nhiều càng tốt. Cụ thể,
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
15 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
16 luôn trả về
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
17, ngay cả khi
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
13 là số 0 hoặc NaN. Nếu cả
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
13 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
14 đều hữu hạn,
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
13 âm và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
14 không phải là số nguyên thì
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
23 không xác định và tăng
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4

Không giống như toán tử

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
25 tích hợp sẵn,
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
26 chuyển đổi cả hai đối số của nó thành kiểu
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
27. Sử dụng hàm
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
25 hoặc hàm
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
29 tích hợp để tính toán các lũy thừa số nguyên chính xác

Đã thay đổi trong phiên bản 3. 11. Các trường hợp đặc biệt

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
30 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
31 đã được thay đổi thành trả về
math.nan is float['nan']
46 thay vì nâng cao
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4, để thống nhất với IEEE 754.

toán học. sqrt[x]

Trả về căn bậc hai của x

Hàm lượng giác¶

toán học. acos[x]

Trả về cung cosin của x, tính bằng radian. Kết quả là giữa

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
37 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
35

toán học. asin[x]

Trả về cung sin của x, tính bằng radian. Kết quả là giữa

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
36 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
37

toán học. atan[x]

Trả về cung tiếp tuyến của x, tính bằng radian. Kết quả là giữa

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
36 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
37

toán học. atan2[y , x]

Trả về

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
40, tính bằng radian. Kết quả là giữa
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
41 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
35. Vectơ trong mặt phẳng từ gốc tọa độ đến điểm
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
43 tạo với trục X dương một góc. Điểm của
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
44 là nó đã biết dấu của cả hai đầu vào, vì vậy nó có thể tính góc tọa độ chính xác cho góc. Ví dụ:
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
45 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
46 đều là
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
47, nhưng
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
48 là
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
49

toán học. cos[x]

Trả về cosin của x radian

toán học. dist[p , q]

Trả về khoảng cách Euclide giữa hai điểm p và q, mỗi điểm được cho dưới dạng một chuỗi tọa độ [hoặc có thể lặp lại]. Hai điểm phải có cùng chiều

Gần tương đương với

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
3

Mới trong phiên bản 3. 8

toán học. hypot[*tọa độ]

Trả về định mức Euclide,

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
50. Đây là độ dài của vectơ từ gốc tọa độ đến điểm được cho bởi tọa độ

Đối với một điểm hai chiều

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
43, điều này tương đương với việc tính toán cạnh huyền của một tam giác vuông bằng cách sử dụng định lý Pythagore,
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
52

Đã thay đổi trong phiên bản 3. 8. Đã thêm hỗ trợ cho điểm n chiều. Trước đây, chỉ hỗ trợ trường hợp hai chiều.

Đã thay đổi trong phiên bản 3. 10. Cải thiện độ chính xác của thuật toán để lỗi tối đa dưới 1 ulp [đơn vị ở vị trí cuối cùng]. Điển hình hơn, kết quả hầu như luôn được làm tròn chính xác trong vòng 1/2 ulp.

toán học. tội lỗi[x]

Trả về sin của x radian

toán học. tan[x]

Trả về tang của x radian

Chuyển đổi góc¶

toán học. độ[x]

Chuyển đổi góc x từ radian sang độ

toán học. radian[x]

Chuyển đổi góc x từ độ sang radian

Các hàm hypebol¶

Các hàm hyperbol tương tự như các hàm lượng giác dựa trên các hyperbol thay vì các đường tròn

toán học. acosh[x]

Trả về cosin hyperbol nghịch đảo của x

toán học. asinh[x]

Trả về sin hyperbol nghịch đảo của x

toán học. atanh[x]

Trả về tang hyperbol nghịch đảo của x

toán học. cosh[x]

Trả về cosin hyperbol của x

toán học. sinh[x]

Trả về sin hyperbol của x

toán học. tánh[x]

Trả về tang hyperbol của x

Chức năng đặc biệt¶

toán học. erf[x]

Trả về hàm lỗi tại x

Hàm

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
53 có thể được sử dụng để tính toán các hàm thống kê truyền thống, chẳng hạn như phân phối chuẩn chuẩn tích lũy

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
3

Mới trong phiên bản 3. 2

toán học. erfc[x]

Trả về hàm lỗi bổ sung tại x. Hàm lỗi bổ sung được định nghĩa là

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
54. Nó được sử dụng cho các giá trị lớn của x trong đó phép trừ từ một sẽ gây ra sự mất ý nghĩa

Mới trong phiên bản 3. 2

toán học. gamma[x]

Trả về hàm Gamma tại x

Mới trong phiên bản 3. 2

toán học. lgamma[x]

Trả về logarit tự nhiên của giá trị tuyệt đối của hàm Gamma tại x

Mới trong phiên bản 3. 2

Hằng số¶

toán học. pi

Hằng số toán học π = 3. 141592…, theo độ chính xác có sẵn

toán học. e

Hằng số toán học e = 2. 718281…, với độ chính xác có sẵn

toán học. tau

Hằng số toán học τ = 6. 283185…, theo độ chính xác có sẵn. Tau là một hằng số hình tròn bằng 2π, tỷ số giữa chu vi hình tròn và bán kính của nó. Để tìm hiểu thêm về Tau, hãy xem video của Vi Hart Pi is [vẫn] Sai, và bắt đầu kỷ niệm ngày Tau bằng cách ăn gấp đôi chiếc bánh

Mới trong phiên bản 3. 6

toán học. inf

Một dấu phẩy động vô cực dương. [Đối với vô cực âm, sử dụng

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
55. ] Tương đương với đầu ra của
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
56

Mới trong phiên bản 3. 5

toán học. nan

Giá trị dấu chấm động “không phải là số” [NaN]. Tương đương với đầu ra của

>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
57. Do các yêu cầu của tiêu chuẩn IEEE-754,
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
58 và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
57 không được coi là bằng với bất kỳ giá trị số nào khác, kể cả chính chúng. Để kiểm tra xem một số có phải là NaN hay không, hãy sử dụng hàm
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
60 để kiểm tra NaN thay vì
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
61 hoặc
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
62. Thí dụ

math.nan is float['nan']
4

Đã thay đổi trong phiên bản 3. 11. Hiện tại nó luôn có sẵn.

Mới trong phiên bản 3. 5

Chi tiết triển khai CPython. Mô-đun

// float['nan'] will call this function to get the value of float object.
double
_Py_parse_inf_or_nan[const char *p, char **endptr]
{
    ...
    else if [case_insensitive_match[s, "nan"]] {
        s += 3;
        retval = negate ? -Py_NAN : Py_NAN;
    }
    ...
    return retval;
}

// Py_NAN: Value that evaluates to a quiet Not-a-Number [NaN].
#if !defined[Py_NAN]
#  if _Py__has_builtin[__builtin_nan]
     // Built-in implementation of the ISO C99 function nan[]: quiet NaN.
#    define Py_NAN [__builtin_nan[""]]
#else
     // Use C99 NAN constant: quiet Not-A-Number.
     // NAN is a float, Py_NAN is a double: cast to double.
#    define Py_NAN [[double]NAN]
#  endif
#endif
47 bao gồm hầu hết các trình bao bọc mỏng xung quanh các hàm thư viện toán học C của nền tảng. Hành vi trong các trường hợp đặc biệt tuân theo Phụ lục F của tiêu chuẩn C99 khi thích hợp. Việc triển khai hiện tại sẽ tăng
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
4 cho các hoạt động không hợp lệ như
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
65 hoặc
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
66 [trong đó C99 Phụ lục F khuyến nghị báo hiệu hoạt động không hợp lệ hoặc chia cho 0] và
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
67 cho các kết quả bị tràn [ví dụ:
>>> from math import exp, expm1
>>> exp[1e-5] - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1[1e-5]    # result accurate to full precision
1.0000050000166668e-05
68]. Một NaN sẽ không được trả về từ bất kỳ hàm nào ở trên trừ khi một hoặc nhiều đối số đầu vào là NaN;

Lưu ý rằng Python không cố gắng phân biệt NaN báo hiệu với NaN yên tĩnh và hành vi báo hiệu NaN vẫn chưa được chỉ định. Hành vi điển hình là coi tất cả các NaN như thể chúng im lặng

NaN trong float là gì?

NaN là viết tắt của Không phải là số và là một trong những cách phổ biến để biểu thị giá trị còn thiếu trong dữ liệu. Nó là một giá trị dấu phẩy động đặc biệt và không thể chuyển đổi thành bất kỳ loại nào khác ngoài float. Giá trị NaN là một trong những vấn đề chính trong Phân tích dữ liệu.

float ['inf'] trong Python là gì?

Biểu diễn vô cực dưới dạng Số nguyên trong python . Người ta có thể sử dụng float['inf'] làm số nguyên để biểu thị nó là vô cùng. float values can be used to represent an infinite integer. One can use float['inf'] as an integer to represent it as infinity.

NaN có phải là gấu trúc nổi không?

nan. Trong Làm việc với dữ liệu bị thiếu, chúng tôi thấy rằng gấu trúc chủ yếu sử dụng NaN để biểu thị dữ liệu bị thiếu. Vì NaN là số thực nên điều này buộc một mảng các số nguyên có bất kỳ giá trị nào bị thiếu trở thành dấu phẩy động.

Làm cách nào để kiểm tra xem giá trị có phải là float NaN không?

Bài toán . phương thức isnan[] kiểm tra xem một giá trị có phải là NaN [Không phải là Số] hay không. Phương thức này trả về True nếu giá trị được chỉ định là NaN, nếu không, nó trả về Sai.

Chủ Đề