diff --git a/tutorial/floatingpoint.po b/tutorial/floatingpoint.po index d1e1cb3..61d231a 100644 --- a/tutorial/floatingpoint.po +++ b/tutorial/floatingpoint.po @@ -12,154 +12,195 @@ msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-07-25 12:59+0330\n" -"PO-Revision-Date: 2021-06-28 01:50+0000\n" +"PO-Revision-Date: 2026-08-08 12:04+0330\n" "Last-Translator: Alireza Shabani (Revisto) , 2025\n" -"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/" -"fa/)\n" +"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/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" #: ../../tutorial/floatingpoint.rst:10 msgid "Floating-Point Arithmetic: Issues and Limitations" -msgstr "" +msgstr "حساب ممیز شناور: مشکلات و محدودیت‌ها" #: ../../tutorial/floatingpoint.rst:16 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." +"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 است. این دو کسر مقدار یکسانی دارند " +"و تنها تفاوت واقعی آن‌ها این است که اولی با نمایش کسری در مبنای ۱۰ و دومی با نمایش کسری " +"در مبنای ۲ نوشته شده است." #: ../../tutorial/floatingpoint.rst:23 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." +"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:28 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::" +"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 msgid "0.3" -msgstr "" +msgstr "۰.۳" #: ../../tutorial/floatingpoint.rst:33 ../../tutorial/floatingpoint.rst:37 msgid "or, better, ::" -msgstr "" +msgstr "یا حتی بهتر،::" #: ../../tutorial/floatingpoint.rst:35 msgid "0.33" -msgstr "" +msgstr "۰.۳۳" #: ../../tutorial/floatingpoint.rst:39 msgid "0.333" -msgstr "" +msgstr "۰.۳۳۳" #: ../../tutorial/floatingpoint.rst:41 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." +"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:45 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 ::" +"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 کسری بی‌نهایت تکرارشونده است::" #: ../../tutorial/floatingpoint.rst:49 msgid "0.0001100110011001100110011001100110011001100110011..." -msgstr "" +msgstr "۰.۰.۰۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱۰۰۱۱..." #: ../../tutorial/floatingpoint.rst:51 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." +"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 نزدیک است، اما دقیقاً برابر آن " +"نیست." #: ../../tutorial/floatingpoint.rst:58 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::" +"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 را چاپ می‌کرد، مجبور " +"بود مقدار زیر را نمایش دهد::" #: ../../tutorial/floatingpoint.rst:64 msgid "" ">>> 0.1\n" "0.1000000000000000055511151231257827021181583404541015625" msgstr "" +">>> 0.1\n" +"0.1000000000000000055511151231257827021181583404541015625" #: ../../tutorial/floatingpoint.rst:67 msgid "" -"That is more digits than most people find useful, so Python keeps the number " -"of digits manageable by displaying a rounded value instead:" +"That is more digits than most people find useful, so Python keeps the number of digits " +"manageable by displaying a rounded value instead:" msgstr "" +"این تعداد رقم بیشتر از چیزی است که بیشتر افراد مفید می‌دانند، بنابراین پایتون با نمایش یک " +"مقدار گرد شده، تعداد ارقام را در حد قابل‌مدیریت نگه می‌دارد:" #: ../../tutorial/floatingpoint.rst:70 msgid "" ">>> 1 / 10\n" "0.1" msgstr "" +">>> 1 / 10\n" +"0.1" #: ../../tutorial/floatingpoint.rst:75 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." +"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:78 msgid "" -"Interestingly, there are many different decimal numbers that share the same " -"nearest approximate binary fraction. For example, the numbers ``0.1`` and " +"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.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:86 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``." +"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`` را نمایش دهد." #: ../../tutorial/floatingpoint.rst:91 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)." +"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 "" +"توجه داشته باشید که این موضوع ذاتاً بخشی از ممیز شناور دودویی است: این یک باگ در پایتون " +"نیست و در کد شما نیز اشکالی وجود ندارد. همین رفتار را در تمام زبان‌هایی که از محاسبات " +"ممیز شناور سخت‌افزار شما پشتیبانی می‌کنند خواهید دید (اگرچه برخی زبان‌ها ممکن است این تفاوت " +"را به‌صورت پیش‌فرض یا در همهٔ حالت‌های خروجی نمایش ندهند)." #: ../../tutorial/floatingpoint.rst:97 msgid "" -"For more pleasant output, you may wish to use string formatting to produce a " -"limited number of significant digits:" +"For more pleasant output, you may wish to use string formatting to produce a limited " +"number of significant digits:" msgstr "" +"برای خروجی خواناتر، می‌توانید از قالب‌بندی رشته‌ها استفاده کنید تا تعداد محدودی رقم معنادار " +"تولید شود:" #: ../../tutorial/floatingpoint.rst:100 msgid "" @@ -172,123 +213,172 @@ msgid "" ">>> repr(math.pi)\n" "'3.141592653589793'" msgstr "" +">>> 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'" #: ../../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." +"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:" +"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:117 msgid "" ">>> 0.1 + 0.1 + 0.1 == 0.3\n" "False" msgstr "" +">>> 0.1 + 0.1 + 0.1 == 0.3\n" +"False" #: ../../tutorial/floatingpoint.rst:122 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:" +"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:126 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" #: ../../tutorial/floatingpoint.rst:131 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` می‌تواند برای مقایسهٔ مقادیر تقریبی مفید باشد:" #: ../../tutorial/floatingpoint.rst:134 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" #: ../../tutorial/floatingpoint.rst:139 msgid "" -"Alternatively, the :func:`round` function can be used to compare rough " -"approximations:" -msgstr "" +"Alternatively, the :func:`round` function can be used to compare rough approximations:" +msgstr "روش دیگر این است که برای مقایسهٔ تقریب‌های کلی از تابع :func:`round` استفاده کنید:" #: ../../tutorial/floatingpoint.rst:142 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" #: ../../tutorial/floatingpoint.rst:147 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 " -"`_ 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 `_ for a more complete " +"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 `_ 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 `_ for a more complete " "account of other common surprises." msgstr "" +"محاسبات ممیز شناور دودویی شگفتی‌های زیادی مانند این دارند. مشکل مربوط به \"0.1\" " +"در ادامه، در بخش «خطای نمایش» با جزئیات دقیق توضیح داده شده است. همچنین " +"`Examples of Floating Point Problems `_ " +"را ببینید که خلاصه‌ای قابل‌فهم از نحوهٔ کار ممیز شناور دودویی و مشکلات رایج آن در عمل " +"ارائه می‌دهد. برای توضیح کامل‌تر سایر شگفتی‌های رایج نیز " +"`The Perils of Floating Point `_ را ببینید." #: ../../tutorial/floatingpoint.rst:156 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." +"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 واحد هستند. این مقدار برای بیشتر کارها کاملاً کافی است، اما باید در نظر " +"داشته باشید که این محاسبات، حساب ده‌دهی نیستند و هر عملیات ممیز شناور می‌تواند با یک خطای " +"گرد کردن جدید همراه شود." #: ../../tutorial/floatingpoint.rst:163 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`." +"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` ببینید." #: ../../tutorial/floatingpoint.rst:169 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." +"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:173 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)." +"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:177 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 ." +"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 ." msgstr "" +"اگر استفاده زیادی از عملیات ممیز شناور دارید، بهتر است نگاهی به بسته NumPy و بسیاری از " +"بسته‌های دیگر برای محاسبات ریاضی و آماری که توسط پروژه SciPy ارائه شده‌اند بیندازید. به " +"https://scipy.org مراجعه کنید." #: ../../tutorial/floatingpoint.rst:181 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:" +"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` مقدار " +"یک عدد ممیز شناور را به‌صورت یک کسر نمایش می‌دهد:" #: ../../tutorial/floatingpoint.rst:186 msgid "" @@ -296,59 +386,76 @@ msgid "" ">>> x.as_integer_ratio()\n" "(3537115888337719, 1125899906842624)" msgstr "" +">>> x = 3.14159\n" +">>> x.as_integer_ratio()\n" +"(3537115888337719, 1125899906842624)" #: ../../tutorial/floatingpoint.rst:192 -msgid "" -"Since the ratio is exact, it can be used to losslessly recreate the original " -"value:" +msgid "Since the ratio is exact, it can be used to losslessly recreate the original value:" msgstr "" +"از آنجا که این نسبت دقیق است، می‌توان از آن برای بازسازی مقدار اصلی بدون هیچ‌گونه از دست " +"رفتن اطلاعات استفاده کرد:" #: ../../tutorial/floatingpoint.rst:195 msgid "" ">>> x == 3537115888337719 / 1125899906842624\n" "True" msgstr "" +">>> x == 3537115888337719 / 1125899906842624\n" +"True" #: ../../tutorial/floatingpoint.rst:200 msgid "" -"The :meth:`float.hex` method expresses a float in hexadecimal (base 16), " -"again giving the exact value stored by your computer:" +"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` یک عدد ممیز شناور را به شکل هگزادسیمال (مبنای ۱۶) نمایش می‌دهد و " +"دوباره مقدار دقیقی را که توسط کامپیوتر شما ذخیره شده است ارائه می‌کند:" #: ../../tutorial/floatingpoint.rst:203 msgid "" ">>> x.hex()\n" "'0x1.921f9f01b866ep+1'" msgstr "" +">>> x.hex()\n" +"'0x1.921f9f01b866ep+1'" #: ../../tutorial/floatingpoint.rst:208 msgid "" -"This precise hexadecimal representation can be used to reconstruct the float " -"value exactly:" +"This precise hexadecimal representation can be used to reconstruct the float value " +"exactly:" msgstr "" +"این نمایش دقیق هگزادسیمال می‌تواند برای بازسازی دقیق مقدار عدد ممیز شناور استفاده شود:" #: ../../tutorial/floatingpoint.rst:211 msgid "" ">>> x == float.fromhex('0x1.921f9f01b866ep+1')\n" "True" msgstr "" +">>> x == float.fromhex('0x1.921f9f01b866ep+1')\n" +"True" #: ../../tutorial/floatingpoint.rst:216 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)." +"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) مفید است." #: ../../tutorial/floatingpoint.rst:220 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:" +"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` است که به کاهش از دست رفتن دقت هنگام جمع " +"کردن مقادیر کمک می‌کند. این تابع هنگام اضافه شدن مقادیر به یک مجموع در حال محاسبه، از دقت " +"گسترده‌تر برای مراحل میانی گرد کردن استفاده می‌کند. این موضوع می‌تواند دقت کلی را بهبود دهد " +"تا خطاها به اندازه‌ای انباشته نشوند که روی مجموع نهایی تأثیر بگذارند:" #: ../../tutorial/floatingpoint.rst:226 msgid "" @@ -357,15 +464,22 @@ msgid "" ">>> 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" #: ../../tutorial/floatingpoint.rst:233 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:" +"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` است، اما در موارد غیرمعمولی که مقادیر بزرگ تا حد زیادی " +"یکدیگر را خنثی می‌کنند و مجموع نهایی نزدیک به صفر می‌شود، دقت بیشتری خواهد داشت:" #: ../../tutorial/floatingpoint.rst:239 msgid "" @@ -375,79 +489,107 @@ msgid "" "8.042173697819788e-13\n" ">>> math.fsum(arr) # Single rounding\n" "8.042173697819788e-13\n" -">>> sum(arr) # Multiple roundings in extended " -"precision\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" +"... total += x # Multiple roundings in standard precision\n" "...\n" -">>> total # Straight addition has no correct " -"digits!\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))) # 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" #: ../../tutorial/floatingpoint.rst:260 msgid "Representation Error" -msgstr "" +msgstr "خطای نمایش" #: ../../tutorial/floatingpoint.rst:262 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." +"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:266 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." +":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 و بسیاری زبان‌های دیگر) اغلب عدد " +"اعشاری دقیقی را که انتظار دارید نمایش نمی‌دهد." #: ../../tutorial/floatingpoint.rst:271 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 ::" +"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* یک عدد صحیح با دقیقاً ۵۳ بیت است. بازنویسی ::" #: ../../tutorial/floatingpoint.rst:280 msgid "1 / 10 ~= J / (2**N)" -msgstr "" +msgstr "1 / 10 ~= J / (2**N)" #: ../../tutorial/floatingpoint.rst:282 msgid "as ::" -msgstr "" +msgstr "به شکل ::" #: ../../tutorial/floatingpoint.rst:284 msgid "J ~= 2**N / 10" -msgstr "" +msgstr "J ~= 2**N / 10" #: ../../tutorial/floatingpoint.rst:286 msgid "" -"and recalling that *J* has exactly 53 bits (is ``>= 2**52`` but ``< " -"2**53``), the best value for *N* is 56:" +"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* برابر ۵۶ است:" #: ../../tutorial/floatingpoint.rst:289 msgid "" ">>> 2**52 <= 2**56 // 10 < 2**53\n" "True" msgstr "" +">>> 2**52 <= 2**56 // 10 < 2**53\n" +"True" #: ../../tutorial/floatingpoint.rst:294 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:" +"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*، همان خارج‌قسمت گرد شده است:" #: ../../tutorial/floatingpoint.rst:297 msgid "" @@ -455,87 +597,105 @@ msgid "" ">>> r\n" "6" msgstr "" +">>> q, r = divmod(2**56, 10)\n" +">>> r\n" +"6" #: ../../tutorial/floatingpoint.rst:303 msgid "" -"Since the remainder is more than half of 10, the best approximation is " -"obtained by rounding up:" +"Since the remainder is more than half of 10, the best approximation is obtained by " +"rounding up:" msgstr "" +"از آنجا که باقی‌مانده بیشتر از نصف ۱۰ است، بهترین تقریب با گرد کردن به بالا به دست می‌آید:" #: ../../tutorial/floatingpoint.rst:306 msgid "" ">>> q+1\n" "7205759403792794" msgstr "" +">>> q+1\n" +"7205759403792794" #: ../../tutorial/floatingpoint.rst:313 -msgid "" -"Therefore the best possible approximation to 1/10 in IEEE 754 double " -"precision is::" -msgstr "" +msgid "Therefore the best possible approximation to 1/10 in IEEE 754 double precision is::" +msgstr "بنابراین بهترین تقریب ممکن برای \"1/10\" در دقت مضاعف IEEE 754 برابر است با::" #: ../../tutorial/floatingpoint.rst:316 msgid "7205759403792794 / 2 ** 56" -msgstr "" +msgstr "7205759403792794 / 2 ** 56" #: ../../tutorial/floatingpoint.rst:318 -msgid "" -"Dividing both the numerator and denominator by two reduces the fraction to::" -msgstr "" +msgid "Dividing both the numerator and denominator by two reduces the fraction to::" +msgstr "تقسیم صورت و مخرج بر دو، این کسر را به شکل زیر ساده می‌کند::" #: ../../tutorial/floatingpoint.rst:320 msgid "3602879701896397 / 2 ** 55" -msgstr "" +msgstr "3602879701896397 / 2 ** 55" #: ../../tutorial/floatingpoint.rst:322 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!" +"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:326 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:" +"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:329 msgid "" ">>> 0.1 * 2 ** 55\n" "3602879701896397.0" msgstr "" +">>> 0.1 * 2 ** 55\n" +"3602879701896397.0" #: ../../tutorial/floatingpoint.rst:334 msgid "" -"If we multiply that fraction by 10\\*\\*55, we can see the value out to 55 " -"decimal digits:" +"If we multiply that fraction by 10\\*\\*55, we can see the value out to 55 decimal " +"digits:" msgstr "" +"اگر آن کسر را در 10**55 ضرب کنیم، می‌توانیم مقدار را تا ۵۵ رقم اعشار مشاهده کنیم:" #: ../../tutorial/floatingpoint.rst:337 msgid "" ">>> 3602879701896397 * 10 ** 55 // 2 ** 55\n" "1000000000000000055511151231257827021181583404541015625" msgstr "" +">>> 3602879701896397 * 10 ** 55 // 2 ** 55\n" +"1000000000000000055511151231257827021181583404541015625" #: ../../tutorial/floatingpoint.rst:342 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:" +"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" +"به‌جای نمایش مقدار کامل اعشاری، بسیاری از زبان‌ها (از جمله نسخه‌های قدیمی‌تر پایتون) نتیجه " +"را تا ۱۷ رقم معنادار گرد می‌کنند:" #: ../../tutorial/floatingpoint.rst:347 msgid "" ">>> format(0.1, '.17f')\n" "'0.10000000000000001'" msgstr "" +">>> format(0.1, '.17f')\n" +"'0.10000000000000001'" #: ../../tutorial/floatingpoint.rst:352 -msgid "" -"The :mod:`fractions` and :mod:`decimal` modules make these calculations easy:" -msgstr "" +msgid "The :mod:`fractions` and :mod:`decimal` modules make these calculations easy:" +msgstr "ماژول‌های :mod:`fractions` و :mod:`decimal` انجام این محاسبات را آسان می‌کنند:" #: ../../tutorial/floatingpoint.rst:355 msgid "" @@ -554,3 +714,17 @@ msgid "" ">>> 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'"