Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Floor division return value
#8
(Nov-26-2020, 10:12 AM)Chirumer Wrote: So I changed the question from "why // changed" to "why // works the way it does"

If you follow the documentation then you find:

- Documentation > The Python Language Reference > 6. Expressions > 6.1. Arithmetic Conversions:

Quote:When a description of an arithmetic operator below uses the phrase “the numeric arguments are converted to a common type”, this means that the operator implementation for built-in types works as follows:

  • If either argument is a complex number, the other is converted to complex;
  • otherwise, if either argument is a floating point number, the other is converted to floating point;
  • otherwise, both must be integers and no conversion is necessary.
Some additional rules apply for certain operators (e.g., a string as a left argument to the ‘%’ operator). Extensions must define their own conversion behavior.

On the same page, under 6.7. Binary arithmetic operations you will find:

Quote:The / (division) and // (floor division) operators yield the quotient of their arguments. The numeric arguments are first converted to a common type. Division of integers yields a float, while floor division of integers results in an integer; the result is that of mathematical division with the ‘floor’ function applied to the result. Division by zero raises the ZeroDivisionError exception.

It is good practice to read documentation. Even more, if you follow python.org advice then you even keep some stuff under the pillow (documentation)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Floor division return value - by Chirumer - Nov-26-2020, 09:04 AM
RE: Floor division return value - by Axel_Erfurt - Nov-26-2020, 09:28 AM
RE: Floor division return value - by perfringo - Nov-26-2020, 09:29 AM
RE: Floor division return value - by Chirumer - Nov-26-2020, 10:12 AM
RE: Floor division return value - by perfringo - Nov-26-2020, 12:03 PM
RE: Floor division return value - by buran - Nov-26-2020, 09:33 AM
RE: Floor division return value - by DeaD_EyE - Nov-26-2020, 09:50 AM
RE: Floor division return value - by Chirumer - Nov-26-2020, 10:05 AM
RE: Floor division return value - by DeaD_EyE - Nov-26-2020, 02:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 1,340 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  Division questions Dionysis 5 1,102 Feb-14-2023, 02:02 PM
Last Post: Dionysis
  Floor approximation problem in algorithm gradlon93 3 994 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  Division by zero and value of argument Lawu 5 3,208 Jul-01-2022, 02:28 PM
Last Post: Lawu
  Floor division problem with plotting x-axis tick labels Mark17 5 2,163 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Division calcuation with answers to 1decimal place. sik 3 2,156 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 3,101 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Integer division plozaq 2 2,015 Sep-28-2020, 05:49 PM
Last Post: plozaq
  Overcoming ZeroDivisionError: division by zero Error dgrunwal 8 5,129 Jun-12-2020, 01:52 PM
Last Post: dgrunwal
  mapping-camera-coordinates-to-a-2d-floor-plan fauveboyxuuki 0 2,577 Dec-10-2019, 10:34 PM
Last Post: fauveboyxuuki

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020