Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions library/stdtypes.po
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ msgid ""
" s = s.lstrip('-0b') # remove leading zeros and minus sign\n"
" return len(s) # len('100101') --> 6"
msgstr ""
"def bit_length(self):\n"
" s = bin(self) # 二進位表示: bin(-37) --> '-0b100101'\n"
" s = s.lstrip('-0b') # 去除開頭的零和負號\n"
" return len(s) # len('100101') --> 6"

#: ../../library/stdtypes.rst:502
msgid ""
Expand Down Expand Up @@ -1139,6 +1143,7 @@ msgstr ""
msgid ""
"Class method to return a floating-point number constructed from a number *x*."
msgstr ""
"Class method會基於數字 *x* 建構並回傳一個浮點數。"
Comment thread
10622130 marked this conversation as resolved.
Outdated

#: ../../library/stdtypes.rst:648
msgid ""
Expand All @@ -1147,13 +1152,17 @@ msgid ""
"returned. If the argument is outside the range of a Python float, an :exc:"
"`OverflowError` will be raised."
msgstr ""
"如果參數是整數或浮點數,將回傳具有相同值的浮點數(在 Python 浮點數精度範圍內)。"
"如果參數超出 Python 浮點數的範圍,將引發 :exc:`OverflowError`。"

#: ../../library/stdtypes.rst:653
msgid ""
"For a general Python object ``x``, ``float.from_number(x)`` delegates to ``x."
"__float__()``. If :meth:`~object.__float__` is not defined then it falls "
"back to :meth:`~object.__index__`."
msgstr ""
"對於任意 Python 物件 ``x``,``float.from_number(x)`` 會委派給 ``x.__float__()``。"
"若 :meth:`~object.__float__` 未定義,則會退回 :meth:`~object.__index__`。"

#: ../../library/stdtypes.rst:663
msgid ""
Expand Down Expand Up @@ -1309,6 +1318,9 @@ msgid ""
"falls back to :meth:`~object.__float__`. If :meth:`!__float__` is not "
"defined then it falls back to :meth:`~object.__index__`."
msgstr ""
"對於任意 Python 物件 ``x``,``complex.from_number(x)`` 會委派給 ``x.__complex__()``。"
"若 :meth:`~object.__complex__` 未定義,則會退回 :meth:`~object.__float__`。"
"若 :meth:`!__float__` 未定義,則會退回 :meth:`~object.__index__`。"

#: ../../library/stdtypes.rst:761
msgid "Hashing of numeric types"
Expand Down Expand Up @@ -1462,6 +1474,53 @@ msgid ""
" hash_value = -2\n"
" return hash_value"
msgstr ""
"import sys, math\n"
"\n"
"def hash_fraction(m, n):\n"
" \"\"\"Compute the hash of a rational number m / n.\n"
"\n"
" Assumes m and n are integers, with n positive.\n"
" Equivalent to hash(fractions.Fraction(m, n)).\n"
"\n"
" \"\"\"\n"
" P = sys.hash_info.modulus\n"
" # 去除P的公因數。 (但若m和n互質則不需要這一步)\n"
Comment thread
10622130 marked this conversation as resolved.
Outdated
" while m % P == n % P == 0:\n"
" m, n = m // P, n // P\n"
"\n"
" if n % P == 0:\n"
" hash_value = sys.hash_info.inf\n"
" else:\n"
" # 費馬小定理: pow(n, P-1, P) 是 1, 所以\n"
" # pow(n, P-2, P) 會得到n modulo P的反元素.\n"
Comment thread
10622130 marked this conversation as resolved.
Outdated
" hash_value = (abs(m) % P) * pow(n, P - 2, P) % P\n"
" if m < 0:\n"
" hash_value = -hash_value\n"
" if hash_value == -1:\n"
" hash_value = -2\n"
" return hash_value\n"
"\n"
"def hash_float(x):\n"
" \"\"\"Compute the hash of a float x.\"\"\"\n"
"\n"
" if math.isnan(x):\n"
" return object.__hash__(x)\n"
" elif math.isinf(x):\n"
" return sys.hash_info.inf if x > 0 else -sys.hash_info.inf\n"
" else:\n"
" return hash_fraction(*x.as_integer_ratio())\n"
"\n"
"def hash_complex(z):\n"
" \"\"\"Compute the hash of a complex number z.\"\"\"\n"
"\n"
" hash_value = hash_float(z.real) + sys.hash_info.imag * hash_float(z."
"imag)\n"
" # 對 2**sys.hash_info.width 做 signed reduction modulo\n"
" M = 2**(sys.hash_info.width - 1)\n"
" hash_value = (hash_value & (M - 1)) - (hash_value & M)\n"
" if hash_value == -1:\n"
" hash_value = -2\n"
" return hash_value"

#: ../../library/stdtypes.rst:864
msgid "Boolean Type - :class:`bool`"
Expand Down