python / cpython

The Python programming language
https://www.python.org
Other
63.8k stars 30.55k forks source link

Floating point tutorial: "today (November 2000)" #104479

Closed pochmann closed 1 year ago

pochmann commented 1 year ago

Documentation

It says:

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, [...]

That feels really weird, computer documentation written 22.5 years ago. I don't know what to think of that, whether that can be trusted today. I suggest to update that.

I also suggest to not start the next sentence with "754 doubles" but with "IEEE-754 doubles", both for style (don't start a sentence with a digit) and because it reads like a number of doubles instead of the kind of doubles (i.e., like "3 apples").

@mdickinson

Linked PRs

mdickinson commented 1 year ago

Agreed that this could use an update. The statement is still true, of course. (If anything, it's even more true today than when it was written, and is likely to remain so for some time, despite the excitement over things like bfloats and posits.)

How about we just drop the explicit date and the "today"?

Almost all machines use IEEE 754 floating-point arithmetic, [...]

It would also be good to mention the "binary64" format explicitly, since that's the particular IEEE 754 interchange format that we care about and IEEE 754 defines various other formats these days (including decimal formats). The standard doesn't use the term "double precision". (I think it's fine to keep it in quotes, since it's a common way to refer to the binary64 format, but it would be good to say "binary64" as well somewhere to avoid ambiguity.)

And a super-nitpick: "IEEE 754" should not be hyphenated.

rhettinger commented 1 year ago

Perhaps instead of "today", use "most machines since 2000" or somesuch. This might convey that this isn't a new state of affairs.

David-Ademola commented 1 year ago

Since November 2000, IEEE-754 floating point arithmetic is utilized by nearly all machines, and Python floats are predominantly mapped to the IEEE-754 "double precision" format across various platforms. Specifically, 754 doubles are capable of retaining 53 bits of precision, thereby facilitating high-precision calculations.

I feel the above is a better way of writing it. And if you think improvements can be made to it, please do.

ericvsmith commented 1 year ago

I don't think "November 2000" adds anything. The statement was just as true a year before, or a year after. I guess we could drop the month, but it still seems oddly specific to pick 2000 as the time the statement became true.

David-Ademola commented 1 year ago

Ah, I see, that's true, the month isn't needed. And according to Wikipedia, the first standard for floating-point arithmetic, IEEE 754-1985, was published in 1985. So would it be more accurate to say, "Since 1985......."

ericvsmith commented 1 year ago

Only if 1985 is when the statement "IEEE-754 floating point arithmetic is utilized by nearly all machines" became true. I don't think we need to qualify it with a date. It's true now, so let's just leave it at that: no month or year.

David-Ademola commented 1 year ago

Agreed. 🤝🏾

hugovk commented 1 year ago

So something like this?

diff --git a/Doc/tutorial/floatingpoint.rst b/Doc/tutorial/floatingpoint.rst
index 306b1eba3c..17434486d4 100644
--- a/Doc/tutorial/floatingpoint.rst
+++ b/Doc/tutorial/floatingpoint.rst
@@ -269,8 +269,8 @@ 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.

 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
+machines use IEEE 754 floating-point arithmetic, and
+almost all platforms map Python floats to IEEE 754 "double precision".  IEEE 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 ::

Also nitpicks "floating point arithmetic" -> "floating-point arithmetic".

This would be a good PR for a new contributor. @David-Ademola, would you like to give it a go?

pochmann commented 1 year ago

I agree with Raymond that it's useful to convey that this is "stable", i.e., has been the case for a long time. I agree with Eric that "since 2000" is oddly specific and doubtful (unless there was a sudden vast change that year). My proposal, also fixing the other issues:

Current:

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 [...]

Proposal:

Almost all machines use IEEE 754 floating point arithmetic, and almost all platforms map Python floats to IEEE 754 “double precision” binary64 (and this has been the case for decades). IEEE 754 binary64 contains 53 bits of precision, so [...]

David-Ademola commented 1 year ago

Sure @hugovk

hauntsaninja commented 1 year ago

Thanks all!