Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

python halp

Name: Anonymous 2008-02-28 1:39

Quick question /prog/,
I'm just starting out a course at school involving python, and this is the first programming language I have had experience in. I have an exercise asking me to predict the output of expression

int (-8.0 / 3)

and i thought -3 since -8.0/3 = -2.666.. and the integer floors it to -3, but the output is -2. I tried -8/3 integer division and it gives -3.

tl;dr why does
int(-8.0/3) = -2
but
-8/3 = -3

Name: Anonymous 2008-02-28 3:44

-8/3 is a fixed-point division which subtracts 3 from |-8| until the |remainder| becomes <3.
int(), however, follows arithmetic conventions and rounds the result to the nearest odd integer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List