Oh Dear

Jussi Jumppanen jussij at zeusedit.com
Sun Jul 12 18:14:30 PDT 2009


Rainer Deyke Wrote:

> Integer division in Python uses floor division instead of
> truncated division, and to the best of my knowledge has always
> used floor division.  

Based on the results produced by Python 2.6.2 and Python 1.5.1 
this does appear to be the case:

Python Version: 2.6.2 (r262:71600, Jul  1 2009, 22:22:20) [MSC v.1500 32 bit (Intel)]
  
    8  //   3 = 2
    8  // (-3)= -3
  (-8) //   3 = -3
  (-8) // (-3)= 2
    8  %   3  = 2
    8  % (-3) = -1
  (-8) %   3  = 1
  (-8) % (-3) = -2
  
    8  /   3  = 2
    8  / (-3) = -3
  (-8) /   3  = -3
  (-8) / (-3) = 2
    8  %   3  = 2
    8  % (-3) = -1
  (-8) %   3  = 1
  (-8) % (-3) = -2
  
  
Python Version: 1.5.1 (#0, Sep 11 2002, 21:19:56) [MSC 32 bit (Intel)]
  
    8  /   3  = 2
    8  / (-3) = -3
  (-8) /   3  = -3
  (-8) / (-3) = 2
    8  %   3  = 2
    8  % (-3) = -1
  (-8) %   3  = 1
  (-8) % (-3) = -2

Cheers Jussi

Note: These results where created by running the Zeus/Python 
      script shown below using a very old version of the Zeus 
      and the recent version of Zeus.

import sys
import zeus

def key_macro():
    zeus.screen_update_disable()
    zeus.FileNew()
    zeus.write("Python Version: " + sys.version);

#   This only works for 2.6.2
#         zeus.write("\n\n")
#         zeus.write("  8  //   3 = " + str(  8  //   3 )  + "\n", 0)
#         zeus.write("  8  // (-3)= " + str(  8  // (-3))  + "\n", 0)
#         zeus.write("(-8) //   3 = " + str((-8) //   3 )  + "\n", 0)
#         zeus.write("(-8) // (-3)= " + str((-8) // (-3))  + "\n", 0)
#         zeus.write("  8  %   3  = " + str(  8  %   3  )  + "\n", 0)
#         zeus.write("  8  % (-3) = " + str(  8  % (-3) )  + "\n", 0)
#         zeus.write("(-8) %   3  = " + str((-8) %   3  )  + "\n", 0)
#         zeus.write("(-8) % (-3) = " + str((-8) % (-3) )  + "\n", 0)


    zeus.write("\n\n")
    zeus.write("  8  /   3  = " + str(  8  /   3 )   + "\n", 0)
    zeus.write("  8  / (-3) = " + str(  8  / (-3))   + "\n", 0)
    zeus.write("(-8) /   3  = " + str((-8) /   3 )   + "\n", 0)
    zeus.write("(-8) / (-3) = " + str((-8) / (-3))   + "\n", 0)
    zeus.write("  8  %   3  = " + str(  8  %   3  )  + "\n", 0)
    zeus.write("  8  % (-3) = " + str(  8  % (-3) )  + "\n", 0)
    zeus.write("(-8) %   3  = " + str((-8) %   3  )  + "\n", 0)
    zeus.write("(-8) % (-3) = " + str((-8) % (-3) )  + "\n", 0)

    zeus.screen_update_enable()
    zeus.screen_update()

key_macro() # run the macro




More information about the Digitalmars-d mailing list