-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathfloatingpoint.po
More file actions
402 lines (356 loc) · 21.4 KB
/
floatingpoint.po
File metadata and controls
402 lines (356 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2025, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.11\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-09-22 20:37+0000\n"
"PO-Revision-Date: 2025-09-22 16:51+0000\n"
"Last-Translator: python-doc bot, 2025\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../tutorial/floatingpoint.rst:9
msgid "Floating Point Arithmetic: Issues and Limitations"
msgstr "浮点算术:争议和限制"
#: ../../tutorial/floatingpoint.rst:14
msgid ""
"Floating-point numbers are represented in computer hardware as base 2 "
"(binary) fractions. For example, the **decimal** fraction ``0.125`` has "
"value 1/10 + 2/100 + 5/1000, and in the same way the **binary** fraction "
"``0.001`` has value 0/2 + 0/4 + 1/8. These two fractions have identical "
"values, the only real difference being that the first is written in base 10 "
"fractional notation, and the second in base 2."
msgstr ""
#: ../../tutorial/floatingpoint.rst:21
msgid ""
"Unfortunately, most decimal fractions cannot be represented exactly as "
"binary fractions. A consequence is that, in general, the decimal floating-"
"point numbers you enter are only approximated by the binary floating-point "
"numbers actually stored in the machine."
msgstr ""
"不幸的是,大多数的十进制小数都不能精确地表示为二进制小数。这导致在大多数情况下,你输入的十进制浮点数都只能近似地以二进制浮点数形式储存在计算机中。"
#: ../../tutorial/floatingpoint.rst:26
msgid ""
"The problem is easier to understand at first in base 10. Consider the "
"fraction 1/3. You can approximate that as a base 10 fraction::"
msgstr "用十进制来理解这个问题显得更加容易一些。考虑分数 1/3 。我们可以得到它在十进制下的一个近似值 ::"
#: ../../tutorial/floatingpoint.rst:31 ../../tutorial/floatingpoint.rst:35
msgid "or, better, ::"
msgstr "或者,更近似的,::"
#: ../../tutorial/floatingpoint.rst:39
msgid ""
"and so on. No matter how many digits you're willing to write down, the "
"result will never be exactly 1/3, but will be an increasingly better "
"approximation of 1/3."
msgstr "以此类推。结果是无论你写下多少的数字,它都永远不会等于 1/3 ,只是更加更加地接近 1/3 。"
#: ../../tutorial/floatingpoint.rst:43
msgid ""
"In the same way, no matter how many base 2 digits you're willing to use, the"
" decimal value 0.1 cannot be represented exactly as a base 2 fraction. In "
"base 2, 1/10 is the infinitely repeating fraction ::"
msgstr ""
"同样的道理,无论你使用多少位以 2 为基数的数码,十进制的 0.1 都无法精确地表示为一个以 2 为基数的小数。 在以 2 为基数的情况下, 1/10 "
"是一个无限循环小数 ::"
#: ../../tutorial/floatingpoint.rst:49
msgid ""
"Stop at any finite number of bits, and you get an approximation. On most "
"machines today, floats are approximated using a binary fraction with the "
"numerator using the first 53 bits starting with the most significant bit and"
" with the denominator as a power of two. In the case of 1/10, the binary "
"fraction is ``3602879701896397 / 2 ** 55`` which is close to but not exactly"
" equal to the true value of 1/10."
msgstr ""
"在任何一个位置停下,你都只能得到一个近似值。因此,在今天的大部分架构上,浮点数都只能近似地使用二进制小数表示,对应分数的分子使用每 8 字节的前 53 "
"位表示,分母则表示为 2 的幂次。在 1/10 这个例子中,相应的二进制分数是 ``3602879701896397 / 2 ** 55`` ,它很接近"
" 1/10 ,但并不是 1/10 。"
#: ../../tutorial/floatingpoint.rst:56
msgid ""
"Many users are not aware of the approximation because of the way values are "
"displayed. Python only prints a decimal approximation to the true decimal "
"value of the binary approximation stored by the machine. On most machines, "
"if Python were to print the true decimal value of the binary approximation "
"stored for 0.1, it would have to display ::"
msgstr ""
"大部分用户都不会意识到这个差异的存在,因为 Python 只会打印计算机中存储的二进制值的十进制近似值。在大部分计算机中,如果 Python 想把 "
"0.1 的二进制对应的精确十进制打印出来,将会变成这样 ::"
#: ../../tutorial/floatingpoint.rst:65
msgid ""
"That is more digits than most people find useful, so Python keeps the number"
" of digits manageable by displaying a rounded value instead ::"
msgstr "这比大多数人认为有用的数字更多,因此Python通过显示舍入值来保持可管理的位数 ::"
#: ../../tutorial/floatingpoint.rst:71
msgid ""
"Just remember, even though the printed result looks like the exact value of "
"1/10, the actual stored value is the nearest representable binary fraction."
msgstr "牢记,即使输出的结果看起来好像就是 1/10 的精确值,实际储存的值只是最接近 1/10 的计算机可表示的二进制分数。"
#: ../../tutorial/floatingpoint.rst:74
msgid ""
"Interestingly, there are many different decimal numbers that share the same "
"nearest approximate binary fraction. For example, the numbers ``0.1`` and "
"``0.10000000000000001`` and "
"``0.1000000000000000055511151231257827021181583404541015625`` are all "
"approximated by ``3602879701896397 / 2 ** 55``. Since all of these decimal "
"values share the same approximation, any one of them could be displayed "
"while still preserving the invariant ``eval(repr(x)) == x``."
msgstr ""
"有趣的是,有许多不同的十进制数共享相同的最接近的近似二进制小数。例如, ``0.1`` 、 ``0.10000000000000001`` 、 "
"``0.1000000000000000055511151231257827021181583404541015625`` 全都近似于 "
"``3602879701896397 / 2 ** 55`` 。由于所有这些十进制值都具有相同的近似值,因此可以显示其中任何一个,同时仍然保留不变的 "
"``eval(repr(x)) == x`` 。"
#: ../../tutorial/floatingpoint.rst:82
msgid ""
"Historically, the Python prompt and built-in :func:`repr` function would "
"choose the one with 17 significant digits, ``0.10000000000000001``. "
"Starting with Python 3.1, Python (on most systems) is now able to choose the"
" shortest of these and simply display ``0.1``."
msgstr ""
"在历史上,Python 提示符和内置的 :func:`repr` 函数会选择具有 17 位有效数字的来显示,即 "
"``0.10000000000000001``。 从 Python 3.1 开始,Python(在大多数系统上)现在能够选择这些表示中最短的并简单地显示"
" ``0.1`` 。"
#: ../../tutorial/floatingpoint.rst:87
msgid ""
"Note that this is in the very nature of binary floating-point: this is not a"
" bug in Python, and it is not a bug in your code either. You'll see the "
"same kind of thing in all languages that support your hardware's floating-"
"point arithmetic (although some languages may not *display* the difference "
"by default, or in all output modes)."
msgstr ""
"请注意这种情况是二进制浮点数的本质特性:它不是 Python 的错误,也不是你代码中的错误。 "
"你会在所有支持你的硬件中的浮点运算的语言中发现同样的情况(虽然某些语言在默认状态或所有输出模块下都不会 *显示* 这种差异)。"
#: ../../tutorial/floatingpoint.rst:93
msgid ""
"For more pleasant output, you may wish to use string formatting to produce a"
" limited number of significant digits::"
msgstr "想要更美观的输出,你可能会希望使用字符串格式化来产生限定长度的有效位数::"
#: ../../tutorial/floatingpoint.rst:105
msgid ""
"It's important to realize that this is, in a real sense, an illusion: you're"
" simply rounding the *display* of the true machine value."
msgstr "必须重点了解的是,这在实际上只是一个假象:你只是将真正的机器码值进行了舍入操作再 *显示* 而已。"
#: ../../tutorial/floatingpoint.rst:108
msgid ""
"One illusion may beget another. For example, since 0.1 is not exactly 1/10,"
" summing three values of 0.1 may not yield exactly 0.3, either::"
msgstr "一个假象还可能导致另一个假象。 例如,由于这个 0.1 并非真正的 1/10,将三个 0.1 的值相加也不一定能恰好得到 0.3::"
#: ../../tutorial/floatingpoint.rst:114
msgid ""
"Also, since the 0.1 cannot get any closer to the exact value of 1/10 and 0.3"
" cannot get any closer to the exact value of 3/10, then pre-rounding with "
":func:`round` function cannot help::"
msgstr ""
"而且,由于这个 0.1 无法精确表示 1/10 的值而这个 0.3 也无法精确表示 3/10 的值,使用 :func:`round` "
"函数进行预先舍入也是没用的::"
#: ../../tutorial/floatingpoint.rst:121
msgid ""
"Though the numbers cannot be made closer to their intended exact values, the"
" :func:`round` function can be useful for post-rounding so that results with"
" inexact values become comparable to one another::"
msgstr "虽然这些小数无法精确表示其所要代表的实际值,:func:`round` 函数还是可以用来“事后舍入”,使得实际的结果值可以做相互比较::"
#: ../../tutorial/floatingpoint.rst:128
msgid ""
"Binary floating-point arithmetic holds many surprises like this. The "
"problem with \"0.1\" is explained in precise detail below, in the "
"\"Representation Error\" section. See `Examples of Floating Point Problems "
"<https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/>`_ for"
" a pleasant summary of how binary floating-point works and the kinds of "
"problems commonly encountered in practice. Also see `The Perils of Floating"
" Point <http://www.indowsway.com/floatingpoint.htm>`_ for a more complete "
"account of other common surprises."
msgstr ""
"二进制浮点运算会有许多这样令人惊讶的情况。 有关 \"0.1\" 的问题会在下面 \"表示性错误\" 一节中更精确详细地描述。 请参阅 "
"`Examples of Floating Point Problems "
"<https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/>`_ "
"获取针对二进制浮点运算机制及在实践中各种常见问题的概要说明。 还可参阅 `The Perils of Floating Point "
"<http://www.indowsway.com/floatingpoint.htm>`_ 获取其他常见意外现象的更完整介绍。"
#: ../../tutorial/floatingpoint.rst:137
msgid ""
"As that says near the end, \"there are no easy answers.\" Still, don't be "
"unduly wary of floating-point! The errors in Python float operations are "
"inherited from the floating-point hardware, and on most machines are on the "
"order of no more than 1 part in 2\\*\\*53 per operation. That's more than "
"adequate for most tasks, but you do need to keep in mind that it's not "
"decimal arithmetic and that every float operation can suffer a new rounding "
"error."
msgstr ""
"正如那篇文章的结尾所言,“对此问题并无简单的答案。” 但是也不必过于担心浮点数的问题! Python "
"浮点运算中的错误是从浮点运算硬件继承而来,而在大多数机器上每次浮点运算得到的 2\\*\\*53 数码位都会被作为 1 个整体来处理。 "
"这对大多数任务来说都已足够,但你确实需要记住它并非十进制算术,且每次浮点运算都可能会导致新的舍入错误。"
#: ../../tutorial/floatingpoint.rst:144
msgid ""
"While pathological cases do exist, for most casual use of floating-point "
"arithmetic you'll see the result you expect in the end if you simply round "
"the display of your final results to the number of decimal digits you "
"expect. :func:`str` usually suffices, and for finer control see the "
":meth:`str.format` method's format specifiers in :ref:`formatstrings`."
msgstr ""
"虽然病态的情况确实存在,但对于大多数正常的浮点运算使用来说,你只需简单地将最终显示的结果舍入为你期望的十进制数值即可得到你期望的结果。 "
":func:`str` 通常已足够,对于更精度的控制可参看 :ref:`formatstrings` 中 :meth:`str.format` "
"方法的格式描述符。"
#: ../../tutorial/floatingpoint.rst:150
msgid ""
"For use cases which require exact decimal representation, try using the "
":mod:`decimal` module which implements decimal arithmetic suitable for "
"accounting applications and high-precision applications."
msgstr "对于需要精确十进制表示的使用场景,请尝试使用 :mod:`decimal` 模块,该模块实现了适合会计应用和高精度应用的十进制运算。"
#: ../../tutorial/floatingpoint.rst:154
msgid ""
"Another form of exact arithmetic is supported by the :mod:`fractions` module"
" which implements arithmetic based on rational numbers (so the numbers like "
"1/3 can be represented exactly)."
msgstr ""
"另一种形式的精确运算由 :mod:`fractions` 模块提供支持,该模块实现了基于有理数的算术运算(因此可以精确表示像 1/3 这样的数值)。"
#: ../../tutorial/floatingpoint.rst:158
msgid ""
"If you are a heavy user of floating-point operations you should take a look "
"at the NumPy package and many other packages for mathematical and "
"statistical operations supplied by the SciPy project. See "
"<https://scipy.org>."
msgstr ""
"如果你是浮点运算的重度用户那么你应当了解一下 NumPy 包以及由 SciPy 项目所提供的许多其他数学和统计运算包。 参见 "
"<https://scipy.org>。"
#: ../../tutorial/floatingpoint.rst:162
msgid ""
"Python provides tools that may help on those rare occasions when you really "
"*do* want to know the exact value of a float. The "
":meth:`float.as_integer_ratio` method expresses the value of a float as a "
"fraction::"
msgstr ""
"Python 也提供了一些工具,可以在你真的 *想要* 知道一个浮点数精确值的少数情况下提供帮助。 例如 "
":meth:`float.as_integer_ratio` 方法会将浮点数表示为一个分数::"
#: ../../tutorial/floatingpoint.rst:171
msgid ""
"Since the ratio is exact, it can be used to losslessly recreate the original"
" value::"
msgstr "由于这是一个精确的比值,它可以被用来无损地重建原始值::"
#: ../../tutorial/floatingpoint.rst:177
msgid ""
"The :meth:`float.hex` method expresses a float in hexadecimal (base 16), "
"again giving the exact value stored by your computer::"
msgstr ":meth:`float.hex` 方法会以十六进制(以 16 为基数)来表示浮点数,同样能给出保存在你的计算机中的精确值::"
#: ../../tutorial/floatingpoint.rst:183
msgid ""
"This precise hexadecimal representation can be used to reconstruct the float"
" value exactly::"
msgstr "这种精确的十六进制表示法可被用来精确地重建浮点值::"
#: ../../tutorial/floatingpoint.rst:189
msgid ""
"Since the representation is exact, it is useful for reliably porting values "
"across different versions of Python (platform independence) and exchanging "
"data with other languages that support the same format (such as Java and "
"C99)."
msgstr ""
"由于这种表示法是精确的,它适用于跨越不同版本(平台无关)的 Python 移植数值,以及与支持相同格式的其他语言(例如 Java 和 C99)交换数据."
#: ../../tutorial/floatingpoint.rst:193
msgid ""
"Another helpful tool is the :func:`math.fsum` function which helps mitigate "
"loss-of-precision during summation. It tracks \"lost digits\" as values are"
" added onto a running total. That can make a difference in overall accuracy"
" so that the errors do not accumulate to the point where they affect the "
"final total:"
msgstr ""
"另一个有用的工具是 :func:`math.fsum` 函数,它有助于减少求和过程中的精度损失。 它会在数值被添加到总计值的时候跟踪“丢失的位”。 "
"这可以很好地保持总计值的精确度, 使得错误不会积累到能影响结果总数的程度:"
#: ../../tutorial/floatingpoint.rst:207
msgid "Representation Error"
msgstr "表示性错误"
#: ../../tutorial/floatingpoint.rst:209
msgid ""
"This section explains the \"0.1\" example in detail, and shows how you can "
"perform an exact analysis of cases like this yourself. Basic familiarity "
"with binary floating-point representation is assumed."
msgstr "本小节将详细解释 \"0.1\" 的例子,并说明你可以怎样亲自对此类情况进行精确分析。 假定前提是已基本熟悉二进制浮点表示法。"
#: ../../tutorial/floatingpoint.rst:213
msgid ""
":dfn:`Representation error` refers to the fact that some (most, actually) "
"decimal fractions cannot be represented exactly as binary (base 2) "
"fractions. This is the chief reason why Python (or Perl, C, C++, Java, "
"Fortran, and many others) often won't display the exact decimal number you "
"expect."
msgstr ""
":dfn:`表示性错误` 是指某些(其实是大多数)十进制小数无法以二进制(以 2 为基数的计数制)精确表示这一事实造成的错误。 这就是为什么 "
"Python(或者 Perl、C、C++、Java、Fortran 以及许多其他语言)经常不会显示你所期待的精确十进制数值的主要原因。"
#: ../../tutorial/floatingpoint.rst:218
msgid ""
"Why is that? 1/10 is not exactly representable as a binary fraction. Since"
" at least 2000, almost all machines use IEEE 754 binary floating-point "
"arithmetic, and almost all platforms map Python floats to IEEE 754 binary64 "
"\"double precision\" values. IEEE 754 binary64 values contain 53 bits of "
"precision, so on input the computer strives to convert 0.1 to the closest "
"fraction it can of the form *J*/2**\\ *N* where *J* is an integer containing"
" exactly 53 bits. Rewriting ::"
msgstr ""
"为什么会这样? 1/10 是无法用二进制小数精确表示的。 至少从 2000 年起,几乎所有机器都使用 IEEE 754 "
"二进制浮点运算标准,而几乎所有系统平台都将 Python 浮点数映射为 IEEE 754 binary64 \"双精度\" 值。 IEEE 754 "
"binary64 值包含 53 位精度,因此在输入时计算机会尽量将 0.1 转换为以 *J*/2**\\ *N* 形式所能表示的最接近的小数,其中 "
"*J* 为恰好包含 53 比特位的整数。 重新将 ::"
#: ../../tutorial/floatingpoint.rst:229
msgid "as ::"
msgstr "写为 ::"
#: ../../tutorial/floatingpoint.rst:233
msgid ""
"and recalling that *J* has exactly 53 bits (is ``>= 2**52`` but ``< "
"2**53``), the best value for *N* is 56::"
msgstr "并且由于 *J* 恰好有 53 位 (即 ``>= 2**52`` 但 ``< 2**53``),*N* 的最佳值为 56::"
#: ../../tutorial/floatingpoint.rst:239
msgid ""
"That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits."
" The best possible value for *J* is then that quotient rounded::"
msgstr "也就是说,56 是唯一的 *N* 值能令 *J* 恰好有 53 位。 这样 *J* 的最佳可能值就是经过舍入的商::"
#: ../../tutorial/floatingpoint.rst:246
msgid ""
"Since the remainder is more than half of 10, the best approximation is "
"obtained by rounding up::"
msgstr "由于余数超过 10 的一半,最佳近似值可通过四舍五入获得::"
#: ../../tutorial/floatingpoint.rst:252
msgid ""
"Therefore the best possible approximation to 1/10 in IEEE 754 double "
"precision is::"
msgstr "因此在 IEEE 754 双精度下可能达到的 1/10 的最佳近似值为::"
#: ../../tutorial/floatingpoint.rst:257
msgid ""
"Dividing both the numerator and denominator by two reduces the fraction to::"
msgstr "分子和分母都除以二则结果小数为::"
#: ../../tutorial/floatingpoint.rst:261
msgid ""
"Note that since we rounded up, this is actually a little bit larger than "
"1/10; if we had not rounded up, the quotient would have been a little bit "
"smaller than 1/10. But in no case can it be *exactly* 1/10!"
msgstr ""
"请注意由于我们做了向上舍入,这个结果实际上略大于 1/10;如果我们没有向上舍入,则商将会略小于 1/10。 但无论如何它都不会是 *精确的* "
"1/10!"
#: ../../tutorial/floatingpoint.rst:265
msgid ""
"So the computer never \"sees\" 1/10: what it sees is the exact fraction "
"given above, the best IEEE 754 double approximation it can get:"
msgstr "因此计算机永远不会 \"看到\" 1/10: 它实际看到的就是上面所给出的小数,即它能达到的最佳 IEEE 754 双精度近似值:"
#: ../../tutorial/floatingpoint.rst:271
msgid ""
"If we multiply that fraction by 10\\*\\*55, we can see the value out to 55 "
"decimal digits::"
msgstr "如果我们将该小数乘以 10\\*\\*55,我们可以看到该值输出为 55 位的十进制数::"
#: ../../tutorial/floatingpoint.rst:277
msgid ""
"meaning that the exact number stored in the computer is equal to the decimal"
" value 0.1000000000000000055511151231257827021181583404541015625. Instead of"
" displaying the full decimal value, many languages (including older versions"
" of Python), round the result to 17 significant digits::"
msgstr ""
"这意味着存储在计算机中的确切数值等于十进制数值 "
"0.1000000000000000055511151231257827021181583404541015625。 许多语言(包括较旧版本的 "
"Python)都不会显示这个完整的十进制数值,而是将结果舍入为 17 位有效数字::"
#: ../../tutorial/floatingpoint.rst:285
msgid ""
"The :mod:`fractions` and :mod:`decimal` modules make these calculations "
"easy::"
msgstr ":mod:`fractions` 和 :mod:`decimal` 模块可令进行此类计算更加容易::"