-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfloatingpoint.po
More file actions
403 lines (327 loc) · 32.9 KB
/
Copy pathfloatingpoint.po
File metadata and controls
403 lines (327 loc) · 32.9 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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Alireza Shabani (Revisto) <theRevisto@gmail.com>, 2025
# Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-08-18 04:30+0000\n"
"PO-Revision-Date: 2026-08-15 07:23+0330\n"
"Last-Translator: Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026\n"
"Language-Team: Persian (https://github.com/revisto/python-docs-fa/)\n"
"Language: fa\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.6\n"
msgid "Floating-Point Arithmetic: Issues and Limitations"
msgstr "حساب ممیز شناور: مشکلات و محدودیتها"
msgid "Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. For example, the **decimal** fraction ``0.625`` has value 6/10 + 2/100 + 5/1000, and in the same way the **binary** fraction ``0.101`` has value 1/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.625`` دارای مقدار 6/10 + 2/100 + 5/1000 است و به همین شکل، کسر **دودویی** ``0.101`` دارای مقدار 1/2 + 0/4 + 1/8 است. این دو کسر مقدار یکسانی دارند و تنها تفاوت واقعی آنها این است که اولی با نمایش کسری در مبنای ۱۰ و دومی با نمایش کسری در مبنای ۲ نوشته شده است."
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 "متأسفانه بیشتر کسرهای دهدهی نمیتوانند بهطور دقیق بهصورت کسرهای دودویی نمایش داده شوند. در نتیجه، بهطور کلی، اعداد ممیز شناور دهدهی که وارد میکنید تنها تقریبی از اعداد ممیز شناور دودویی هستند که واقعاً در ماشین ذخیره میشوند."
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 را در نظر بگیرید. میتوانید آن را بهصورت یک کسر دهدهی تقریبی نمایش دهید::"
msgid "0.3"
msgstr "۰.۳"
msgid "or, better, ::"
msgstr "یا حتی بهتر،::"
msgid "0.33"
msgstr "۰.۳۳"
msgid "0.333"
msgstr "۰.۳۳۳"
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 به دست میآید."
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 کسری بینهایت تکرارشونده است::"
msgid "0.0001100110011001100110011001100110011001100110011..."
msgstr "۰.۰۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱..."
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 "اگر در هر تعداد محدود بیت متوقف شوید، یک مقدار تقریبی به دست میآورید. در بیشتر ماشینهای امروزی، اعداد ممیز شناور با استفاده از یک کسر دودویی تقریبی نمایش داده میشوند که صورت آن از ۵۳ بیت اول، از مهمترین بیت شروعشده، تشکیل شده و مخرج آن توانی از ۲ است. در مورد 1/10، کسر دودویی برابر با ``3602879701896397 / 2 ** 55`` است که به مقدار واقعی 1/10 نزدیک است، اما دقیقاً برابر آن نیست."
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 "بسیاری از کاربران به دلیل نحوهٔ نمایش مقادیر، از این تقریب آگاه نیستند. پایتون تنها یک تقریب دهدهی از مقدار دهدهی واقعیِ مقدار دودویی ذخیرهشده در ماشین را چاپ میکند. در بیشتر ماشینها، اگر پایتون مقدار دهدهی واقعیِ تقریب دودویی ذخیرهشده برای 0.1 را چاپ میکرد، مجبور بود مقدار زیر را نمایش دهد::"
msgid ""
">>> 0.1\n"
"0.1000000000000000055511151231257827021181583404541015625"
msgstr ""
">>> 0.1\n"
"0.1000000000000000055511151231257827021181583404541015625"
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 "این تعداد رقم بیشتر از چیزی است که بیشتر افراد مفید میدانند، بنابراین پایتون با نمایش یک مقدار گرد شده، تعداد ارقام را در حد قابلمدیریت نگه میدارد:"
msgid ""
">>> 1 / 10\n"
"0.1"
msgstr ""
">>> 1 / 10\n"
"0.1"
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 به نظر میرسد، مقدار واقعی ذخیرهشده نزدیکترین کسر دودویی قابل نمایش است."
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`` برقرار بماند."
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 "در گذشته، اعلان پایتون و تابع داخلی :func:`repr` مقداری را با 17 رقم معنادار انتخاب میکردند: ``0.10000000000000001``. از پایتون 3.1 به بعد، پایتون (در بیشتر سیستمها) قادر است کوتاهترین مقدار از میان این نمایشها را انتخاب کند و بهسادگی ``0.1`` را نمایش دهد."
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 "توجه داشته باشید که این موضوع ذاتاً بخشی از ممیز شناور دودویی است: این یک باگ در پایتون نیست و در کد شما نیز اشکالی وجود ندارد. همین رفتار را در تمام زبانهایی که از محاسبات ممیز شناور سختافزار شما پشتیبانی میکنند خواهید دید (اگرچه برخی زبانها ممکن است این تفاوت را بهصورت پیشفرض یا در همهٔ حالتهای خروجی نمایش ندهند)."
msgid "For more pleasant output, you may wish to use string formatting to produce a limited number of significant digits:"
msgstr "برای خروجی خواناتر، میتوانید از قالببندی رشتهها استفاده کنید تا تعداد محدودی رقم معنادار تولید شود:"
msgid ""
">>> format(math.pi, '.12g') # give 12 significant digits\n"
"'3.14159265359'\n"
"\n"
">>> format(math.pi, '.2f') # give 2 digits after the point\n"
"'3.14'\n"
"\n"
">>> repr(math.pi)\n"
"'3.141592653589793'"
msgstr ""
">>> format(math.pi, '.12g') # نمایش ۱۲ رقم معنادار\n"
"'3.14159265359'\n"
"\n"
">>> format(math.pi, '.2f') # نمایش ۲ رقم پس از ممیز\n"
"'3.14'\n"
"\n"
">>> repr(math.pi)\n"
"'3.141592653589793'"
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 "مهم است بدانید که این، از یک نظر واقعی، یک توهم است: شما تنها نمایش مقدار واقعی ماشین را گرد میکنید."
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 نشود:"
msgid ""
">>> 0.1 + 0.1 + 0.1 == 0.3\n"
"False"
msgstr ""
">>> 0.1 + 0.1 + 0.1 == 0.3\n"
"False"
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` کمکی نمیکند:"
msgid ""
">>> round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1)\n"
"False"
msgstr ""
">>> round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1)\n"
"False"
msgid "Though the numbers cannot be made closer to their intended exact values, the :func:`math.isclose` function can be useful for comparing inexact values:"
msgstr "اگرچه این اعداد نمیتوانند به مقادیر دقیق موردنظرشان نزدیکتر شوند، تابع :func:`math.isclose` میتواند برای مقایسهٔ مقادیر تقریبی مفید باشد:"
msgid ""
">>> math.isclose(0.1 + 0.1 + 0.1, 0.3)\n"
"True"
msgstr ""
">>> math.isclose(0.1 + 0.1 + 0.1, 0.3)\n"
"True"
msgid "Alternatively, the :func:`round` function can be used to compare rough approximations:"
msgstr "روش دیگر این است که برای مقایسهٔ تقریبهای کلی از تابع :func:`round` استفاده کنید:"
msgid ""
">>> round(math.pi, ndigits=2) == round(22 / 7, ndigits=2)\n"
"True"
msgstr ""
">>> round(math.pi, ndigits=2) == round(22 / 7, ndigits=2)\n"
"True"
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>`_ را ببینید."
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 "همانطور که در پایان آن توضیح داده شده است، «پاسخ سادهای وجود ندارد.» با این حال، نباید بیش از حد از اعداد ممیز شناور بترسید! خطاهای موجود در عملیات float پایتون از سختافزار محاسبات ممیز شناور به ارث میرسند و در بیشتر ماشینها برای هر عملیات، در حدود حداکثر ۱ واحد از هر 2**53 واحد هستند. این مقدار برای بیشتر کارها کاملاً کافی است، اما باید در نظر داشته باشید که این محاسبات، حساب دهدهی نیستند و هر عملیات ممیز شناور میتواند با یک خطای گرد کردن جدید همراه شود."
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` معمولاً کافی است و برای کنترل دقیقتر، مشخصکنندههای قالببندی متد :meth:`str.format` را در :ref:`formatstrings` ببینید."
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` را امتحان کنید. این ماژول محاسبات اعشاری مناسب برای برنامههای حسابداری و کاربردهای با دقت بالا را پیادهسازی میکند."
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 میتوانند بهطور دقیق نمایش داده شوند)."
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 مراجعه کنید."
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 "پایتون ابزارهایی ارائه میدهد که در آن موارد نادری که واقعاً *میخواهید* مقدار دقیق یک عدد ممیز شناور را بدانید، میتوانند کمککننده باشند. متد :meth:`float.as_integer_ratio` مقدار یک عدد ممیز شناور را بهصورت یک کسر نمایش میدهد:"
msgid ""
">>> x = 3.14159\n"
">>> x.as_integer_ratio()\n"
"(3537115888337719, 1125899906842624)"
msgstr ""
">>> x = 3.14159\n"
">>> x.as_integer_ratio()\n"
"(3537115888337719, 1125899906842624)"
msgid "Since the ratio is exact, it can be used to losslessly recreate the original value:"
msgstr "از آنجا که این نسبت دقیق است، میتوان از آن برای بازسازی مقدار اصلی بدون هیچگونه از دست رفتن اطلاعات استفاده کرد:"
msgid ""
">>> x == 3537115888337719 / 1125899906842624\n"
"True"
msgstr ""
">>> x == 3537115888337719 / 1125899906842624\n"
"True"
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` یک عدد ممیز شناور را به شکل هگزادسیمال (مبنای ۱۶) نمایش میدهد و دوباره مقدار دقیقی را که توسط کامپیوتر شما ذخیره شده است ارائه میکند:"
msgid ""
">>> x.hex()\n"
"'0x1.921f9f01b866ep+1'"
msgstr ""
">>> x.hex()\n"
"'0x1.921f9f01b866ep+1'"
msgid "This precise hexadecimal representation can be used to reconstruct the float value exactly:"
msgstr "این نمایش دقیق هگزادسیمال میتواند برای بازسازی دقیق مقدار عدد ممیز شناور استفاده شود:"
msgid ""
">>> x == float.fromhex('0x1.921f9f01b866ep+1')\n"
"True"
msgstr ""
">>> x == float.fromhex('0x1.921f9f01b866ep+1')\n"
"True"
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 "از آنجا که این نمایش دقیق است، برای انتقال مطمئن مقادیر بین نسخههای مختلف پایتون (مستقل از پلتفرم) و تبادل داده با زبانهای دیگری که از همین قالب پشتیبانی میکنند (مانند Java و C99) مفید است."
msgid "Another helpful tool is the :func:`sum` function which helps mitigate loss-of-precision during summation. It uses extended precision for intermediate rounding steps 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:`sum` است که به کاهش از دست رفتن دقت هنگام جمع کردن مقادیر کمک میکند. این تابع هنگام اضافه شدن مقادیر به یک مجموع در حال محاسبه، از دقت گستردهتر برای مراحل میانی گرد کردن استفاده میکند. این موضوع میتواند دقت کلی را بهبود دهد تا خطاها به اندازهای انباشته نشوند که روی مجموع نهایی تأثیر بگذارند:"
msgid ""
">>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0\n"
"False\n"
">>> sum([0.1] * 10) == 1.0\n"
"True"
msgstr ""
">>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0\n"
"False\n"
">>> sum([0.1] * 10) == 1.0\n"
"True"
msgid "The :func:`math.fsum` goes further and tracks all of the \"lost digits\" as values are added onto a running total so that the result has only a single rounding. This is slower than :func:`sum` but will be more accurate in uncommon cases where large magnitude inputs mostly cancel each other out leaving a final sum near zero:"
msgstr "تابع :func:`math.fsum` حتی فراتر میرود و تمام «ارقام از دسترفته» را هنگام اضافه شدن مقادیر به یک مجموع در حال محاسبه دنبال میکند، بهگونهای که نتیجه تنها یک بار گرد میشود. این تابع کندتر از :func:`sum` است، اما در موارد غیرمعمولی که مقادیر بزرگ تا حد زیادی یکدیگر را خنثی میکنند و مجموع نهایی نزدیک به صفر میشود، دقت بیشتری خواهد داشت:"
msgid ""
">>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,\n"
"... -143401161400469.7, 266262841.31058735, -0.003244936839808227]\n"
">>> float(sum(map(Fraction, arr))) # Exact summation with single rounding\n"
"8.042173697819788e-13\n"
">>> math.fsum(arr) # Single rounding\n"
"8.042173697819788e-13\n"
">>> sum(arr) # Multiple roundings in extended precision\n"
"8.042178034628478e-13\n"
">>> total = 0.0\n"
">>> for x in arr:\n"
"... total += x # Multiple roundings in standard precision\n"
"...\n"
">>> total # Straight addition has no correct digits!\n"
"-0.0051575902860057365"
msgstr ""
">>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,\n"
"... -143401161400469.7, 266262841.31058735, -0.003244936839808227]\n"
">>> float(sum(map(Fraction, arr))) # جمع دقیق با یک گرد کردن نهایی\n"
"8.042173697819788e-13\n"
">>> math.fsum(arr) # یک گرد کردن نهایی\n"
"8.042173697819788e-13\n"
">>> sum(arr) # چندین گرد کردن با دقت گسترده\n"
"8.042178034628478e-13\n"
">>> total = 0.0\n"
">>> for x in arr:\n"
"... total += x # چندین گرد کردن با دقت استاندارد\n"
"...\n"
">>> total # جمع مستقیم هیچ رقم صحیحی ندارد!\n"
"-0.0051575902860057365"
msgid "Representation Error"
msgstr "خطای نمایش"
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\" را با جزئیات توضیح میدهد و نشان میدهد که چگونه میتوانید خودتان تحلیل دقیقی از چنین مواردی انجام دهید. فرض بر این است که با نحوه نمایش اعداد ممیز شناور دودویی آشنایی ابتدایی دارید."
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:`Representation error` به این واقعیت اشاره دارد که برخی (در واقع بیشتر) کسرهای دهدهی نمیتوانند بهطور دقیق به شکل کسرهای دودویی (مبنای ۲) نمایش داده شوند. این دلیل اصلی آن است که پایتون (یا Perl، C، C++، Java، Fortran و بسیاری زبانهای دیگر) اغلب عدد اعشاری دقیقی را که انتظار دارید نمایش نمیدهد."
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 نمیتواند بهطور دقیق به شکل یک کسر دودویی نمایش داده شود. از سال ۲۰۰۰ میلادی تاکنون، تقریباً همه ماشینها از محاسبات ممیز شناور دودویی IEEE 754 استفاده میکنند و تقریباً همه پلتفرمها اعداد float پایتون را به مقادیر «دقت مضاعف» \"IEEE 754 binary64\" نگاشت میکنند. مقادیر IEEE 754 binary64 دارای ۵۳ بیت دقت هستند، بنابراین هنگام ورود مقدار، کامپیوتر تلاش میکند \"0.1\" را به نزدیکترین کسری که به شکل *J*/2** *N* است تبدیل کند؛ جایی که *J* یک عدد صحیح با دقیقاً ۵۳ بیت است. بازنویسی ::"
msgid "1 / 10 ~= J / (2**N)"
msgstr "1 / 10 ~= J / (2**N)"
msgid "as ::"
msgstr "به شکل ::"
msgid "J ~= 2**N / 10"
msgstr "J ~= 2**N / 10"
msgid "and recalling that *J* has exactly 53 bits (is ``>= 2**52`` but ``< 2**53``), the best value for *N* is 56:"
msgstr "و با یادآوری اینکه *J* دقیقاً ۵۳ بیت دارد (یعنی ``>= 2**52`` اما ``< 2**53`` است)، بهترین مقدار برای *N* برابر ۵۶ است:"
msgid ""
">>> 2**52 <= 2**56 // 10 < 2**53\n"
"True"
msgstr ""
">>> 2**52 <= 2**56 // 10 < 2**53\n"
"True"
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 "یعنی ۵۶ تنها مقدار *N* است که باعث میشود *J* دقیقاً ۵۳ بیت داشته باشد. سپس بهترین مقدار ممکن برای *J*، همان خارجقسمت گرد شده است:"
msgid ""
">>> q, r = divmod(2**56, 10)\n"
">>> r\n"
"6"
msgstr ""
">>> q, r = divmod(2**56, 10)\n"
">>> r\n"
"6"
msgid "Since the remainder is more than half of 10, the best approximation is obtained by rounding up:"
msgstr "از آنجا که باقیمانده بیشتر از نصف ۱۰ است، بهترین تقریب با گرد کردن به بالا به دست میآید:"
msgid ""
">>> q+1\n"
"7205759403792794"
msgstr ""
">>> q+1\n"
"7205759403792794"
msgid "Therefore the best possible approximation to 1/10 in IEEE 754 double precision is::"
msgstr "بنابراین بهترین تقریب ممکن برای \"1/10\" در دقت مضاعف IEEE 754 برابر است با::"
msgid "7205759403792794 / 2 ** 56"
msgstr "7205759403792794 / 2 ** 56"
msgid "Dividing both the numerator and denominator by two reduces the fraction to::"
msgstr "تقسیم صورت و مخرج بر دو، این کسر را به شکل زیر ساده میکند::"
msgid "3602879701896397 / 2 ** 55"
msgstr "3602879701896397 / 2 ** 55"
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 باشد!"
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 که میتواند به دست آورد:"
msgid ""
">>> 0.1 * 2 ** 55\n"
"3602879701896397.0"
msgstr ""
">>> 0.1 * 2 ** 55\n"
"3602879701896397.0"
msgid "If we multiply that fraction by 10\\*\\*55, we can see the value out to 55 decimal digits:"
msgstr "اگر آن کسر را در 10**55 ضرب کنیم، میتوانیم مقدار را تا ۵۵ رقم اعشار مشاهده کنیم:"
msgid ""
">>> 3602879701896397 * 10 ** 55 // 2 ** 55\n"
"1000000000000000055511151231257827021181583404541015625"
msgstr ""
">>> 3602879701896397 * 10 ** 55 // 2 ** 55\n"
"1000000000000000055511151231257827021181583404541015625"
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 ""
"یعنی مقدار دقیق ذخیرهشده در کامپیوتر برابر با مقدار اعشاری زیر است:\n"
"0.1000000000000000055511151231257827021181583404541015625\n"
"بهجای نمایش مقدار کامل اعشاری، بسیاری از زبانها (از جمله نسخههای قدیمیتر پایتون) نتیجه را تا ۱۷ رقم معنادار گرد میکنند:"
msgid ""
">>> format(0.1, '.17f')\n"
"'0.10000000000000001'"
msgstr ""
">>> format(0.1, '.17f')\n"
"'0.10000000000000001'"
msgid "The :mod:`fractions` and :mod:`decimal` modules make these calculations easy:"
msgstr "ماژولهای :mod:`fractions` و :mod:`decimal` انجام این محاسبات را آسان میکنند:"
msgid ""
">>> from decimal import Decimal\n"
">>> from fractions import Fraction\n"
"\n"
">>> Fraction.from_float(0.1)\n"
"Fraction(3602879701896397, 36028797018963968)\n"
"\n"
">>> (0.1).as_integer_ratio()\n"
"(3602879701896397, 36028797018963968)\n"
"\n"
">>> Decimal.from_float(0.1)\n"
"Decimal('0.1000000000000000055511151231257827021181583404541015625')\n"
"\n"
">>> format(Decimal.from_float(0.1), '.17')\n"
"'0.10000000000000001'"
msgstr ""
">>> from decimal import Decimal\n"
">>> from fractions import Fraction\n"
"\n"
">>> Fraction.from_float(0.1)\n"
"Fraction(3602879701896397, 36028797018963968)\n"
"\n"
">>> (0.1).as_integer_ratio()\n"
"(3602879701896397, 36028797018963968)\n"
"\n"
">>> Decimal.from_float(0.1)\n"
"Decimal('0.1000000000000000055511151231257827021181583404541015625')\n"
"\n"
">>> format(Decimal.from_float(0.1), '.17')\n"
"'0.10000000000000001'"