-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathfloatingpoint.po
More file actions
425 lines (377 loc) · 17.1 KB
/
floatingpoint.po
File metadata and controls
425 lines (377 loc) · 17.1 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2018, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: Python 3.7\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-06-26 18:54+0800\n"
"PO-Revision-Date: 2018-11-20 14:26+0800\n"
"Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 2.1.1\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 ::"
msgstr ""
"在計算機架構中,浮點數透過二進位小數表示。例如說,在十進位小數中:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:19
msgid ""
"has value 1/10 + 2/100 + 5/1000, and in the same way the binary fraction ::"
msgstr ""
"可被分為 1/10 + 2/100 + 5/1000,同樣的道理,二進位小數 :\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:23
msgid ""
"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 ""
"可被分為 0/2 + 0/4 + 1/8。這兩個小數有相同的數值,而唯一真正的不同在於前者以"
"十進位表示,後者以二進位表示。"
#: ../../tutorial/floatingpoint.rst:27
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:32
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 為例,您可以將其近似為十進位小"
"數:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:37 ../../tutorial/floatingpoint.rst:41
msgid "or, better, ::"
msgstr ""
"或者,更好的近似:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:45
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:49
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 ""
"同樣的道理,不論你願意以多少位數表示二進位小數,十進位小數 0.1 都無法被二進位"
"小數精準地表達。在二進位小數中, 1/10 會是一個無限循環小數:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:55
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 ""
"只要您停在任何有限的位數,您就只會得到近似值。而現在大多數的計算機中,浮點數"
"是透過二進位分數近似的,其中分子從最高有效位元使開始用 53 個位元表示,分母則"
"是以二為底的指數。在 1/10 的例子中,二進位分數為 ``3602879701896397 / 2 ** "
"55``,而這樣的表示十分地接近,但不完全等同於 1/10 的真正數值。"
#: ../../tutorial/floatingpoint.rst:62
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 的二"
"進位近似值,它將顯示為:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:71
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 將位數保持在可以接受的範圍,只顯示"
"捨入後的數值:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:77
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,但真正儲存的數值是能表示的二進"
"位分數中,最接近精準數值的數。"
#: ../../tutorial/floatingpoint.rst:80
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:88
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 的提示字元 (prompt) 與內建的 :func:`repr` 函式會選擇上段說明中"
"有 17 個有效位元的數:``0.10000000000000001``。從 Python 3.1 版開始,"
"Python(在大部分的系統上)可以選擇其中最短的數並簡單地顯示為 ``0.1``。"
#: ../../tutorial/floatingpoint.rst:93
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 的錯誤 (bug),更不是您程"
"式碼的錯誤。只要有程式語言支持硬體的浮點數運算,您將會看到同樣的事情出現在其"
"中(雖然某些程式語言預設不\\ *顯示*\\ 差異,或者預設全部輸出)。"
#: ../../tutorial/floatingpoint.rst:99
msgid ""
"For more pleasant output, you may wish to use string formatting to produce a "
"limited number of significant digits::"
msgstr ""
"為求更優雅的輸出,您可能想要使用字串的格式化 (string formatting) 產生限定的有"
"效位數:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:111
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:114
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:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:120
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` 函式捨入並不會有幫助:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:127
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` 函式可以對事後的捨入有所"
"幫助,如此一來,不精確的數值就變得可以互相比較:\n"
"\n"
"::"
#: ../../tutorial/floatingpoint.rst:134
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 `The Perils of Floating Point <http://"
"www.lahey.com/float.htm>`_ for a more complete account of other common "
"surprises."
msgstr ""
"二進位浮點數架構擁有很多這樣的驚喜。底下的「表示法錯誤」章節,詳細的解釋了"
"「0.1」的問題。如果想要其他常見驚喜更完整的描述,可以參考 `The Perils of "
"Floating Point(浮點數的風險) <http://www.lahey.com/float.htm>`_。"
#: ../../tutorial/floatingpoint.rst:139
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 ""
#: ../../tutorial/floatingpoint.rst:146
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 ""
#: ../../tutorial/floatingpoint.rst:152
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 ""
#: ../../tutorial/floatingpoint.rst:156
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 ""
#: ../../tutorial/floatingpoint.rst:160
msgid ""
"If you are a heavy user of floating point operations you should take a look "
"at the Numerical Python package and many other packages for mathematical and "
"statistical operations supplied by the SciPy project. See <https://scipy."
"org>."
msgstr ""
#: ../../tutorial/floatingpoint.rst:164
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 ""
#: ../../tutorial/floatingpoint.rst:173
msgid ""
"Since the ratio is exact, it can be used to losslessly recreate the original "
"value::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:179
msgid ""
"The :meth:`float.hex` method expresses a float in hexadecimal (base 16), "
"again giving the exact value stored by your computer::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:185
msgid ""
"This precise hexadecimal representation can be used to reconstruct the float "
"value exactly::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:191
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 ""
#: ../../tutorial/floatingpoint.rst:195
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 ""
#: ../../tutorial/floatingpoint.rst:209
msgid "Representation Error"
msgstr ""
#: ../../tutorial/floatingpoint.rst:211
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 ""
#: ../../tutorial/floatingpoint.rst:215
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 ""
#: ../../tutorial/floatingpoint.rst:220
msgid ""
"Why is that? 1/10 is not exactly representable as a binary fraction. Almost "
"all machines today (November 2000) use IEEE-754 floating point arithmetic, "
"and almost all platforms map Python floats to IEEE-754 \"double precision"
"\". 754 doubles 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 ""
#: ../../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 ""
#: ../../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 ""
#: ../../tutorial/floatingpoint.rst:246
msgid ""
"Since the remainder is more than half of 10, the best approximation is "
"obtained by rounding up::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:252
msgid ""
"Therefore the best possible approximation to 1/10 in 754 double precision "
"is::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:256
msgid ""
"Dividing both the numerator and denominator by two reduces the fraction to::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:260
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 ""
#: ../../tutorial/floatingpoint.rst:264
msgid ""
"So the computer never \"sees\" 1/10: what it sees is the exact fraction "
"given above, the best 754 double approximation it can get::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:270
msgid ""
"If we multiply that fraction by 10\\*\\*55, we can see the value out to 55 "
"decimal digits::"
msgstr ""
#: ../../tutorial/floatingpoint.rst:276
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 ""
#: ../../tutorial/floatingpoint.rst:284
msgid ""
"The :mod:`fractions` and :mod:`decimal` modules make these calculations "
"easy::"
msgstr ""