mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
[3.13] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122012)
(cherry picked from commit 1a0c7b9ba4
)
This commit is contained in:
parent
225cbee8d8
commit
a45d9051ed
100 changed files with 238 additions and 238 deletions
|
@ -6,7 +6,7 @@
|
|||
.. _tut-fp-issues:
|
||||
|
||||
**************************************************
|
||||
Floating Point Arithmetic: Issues and Limitations
|
||||
Floating-Point Arithmetic: Issues and Limitations
|
||||
**************************************************
|
||||
|
||||
.. sectionauthor:: Tim Peters <tim_one@users.sourceforge.net>
|
||||
|
@ -88,7 +88,7 @@ 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``.
|
||||
|
||||
Note that this is in the very nature of binary floating-point: this is not a bug
|
||||
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
|
||||
|
@ -148,13 +148,13 @@ 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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
|
|
|
@ -62,7 +62,7 @@ For example::
|
|||
20
|
||||
>>> (50 - 5*6) / 4
|
||||
5.0
|
||||
>>> 8 / 5 # division always returns a floating point number
|
||||
>>> 8 / 5 # division always returns a floating-point number
|
||||
1.6
|
||||
|
||||
The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`,
|
||||
|
@ -544,7 +544,7 @@ This example introduces several new features.
|
|||
* The :func:`print` function writes the value of the argument(s) it is given.
|
||||
It differs from just writing the expression you want to write (as we did
|
||||
earlier in the calculator examples) in the way it handles multiple arguments,
|
||||
floating point quantities, and strings. Strings are printed without quotes,
|
||||
floating-point quantities, and strings. Strings are printed without quotes,
|
||||
and a space is inserted between items, so you can format things nicely, like
|
||||
this::
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ Mathematics
|
|||
===========
|
||||
|
||||
The :mod:`math` module gives access to the underlying C library functions for
|
||||
floating point math::
|
||||
floating-point math::
|
||||
|
||||
>>> import math
|
||||
>>> math.cos(math.pi / 4)
|
||||
|
|
|
@ -352,11 +352,11 @@ not want to run a full list sort::
|
|||
|
||||
.. _tut-decimal-fp:
|
||||
|
||||
Decimal Floating Point Arithmetic
|
||||
Decimal Floating-Point Arithmetic
|
||||
=================================
|
||||
|
||||
The :mod:`decimal` module offers a :class:`~decimal.Decimal` datatype for
|
||||
decimal floating point arithmetic. Compared to the built-in :class:`float`
|
||||
decimal floating-point arithmetic. Compared to the built-in :class:`float`
|
||||
implementation of binary floating point, the class is especially helpful for
|
||||
|
||||
* financial applications and other uses which require exact decimal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue