[docs] Incorrect documentation of // (floor) operator

Chris Benson chrisbenson56 at att.net
Sun Feb 10 22:19:56 CET 2013


In my Windows CHM Python 3.3.0 documentation there is a mismatch between the
description and the example of the // operator.

The following text and example appears in Section 3.1.1. Numbers:

To do integer division and get an integer result, discarding any fractional
result, there is another operator, //:

>>> # Integer division returns the floor:

... 7//3

2

>>> 7//-3

-3

 

The # comment at the python prompt is correct. This is the floor operator.
The accompanying text is wrong "discarding any fractional result" is NOT the
definition of the floor operator in the case of negative results (second
example). The text description would be true if 7 // -3 resulted in -2,
which it does NOT. A better text description would be this:

To do integer division (with fractional results rounded down to the next
lower whole number), there is the floor operator written as //

 

In other words, the text description applying precise (non-integral)
division to 7 / -3, results in -2.333333., and discarding any fractional
result, would arrive at the answer -2.

The textual description describes the truncation operator, which in the
second given example has a different result. For a mathematical description
of both the floor and truncation operators, please see
http://en.wikipedia.org/wiki/Floor_and_ceiling_functions

 

With thanks, from Chris Benson.

Three degrees in mathematics, and nearly 40 years programming experience.
Teaching Python 3 to my daughter!

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20130210/4f2e74f1/attachment-0001.html>


More information about the docs mailing list