Skip to content
  • Mathieu Bridon's avatar
    python: Use explicit integer divisions · 9b6746b7
    Mathieu Bridon authored and Dylan Baker's avatar Dylan Baker committed
    
    
    In Python 2, divisions of integers return an integer:
    
        >>> 32 / 4
        8
    
    In Python 3 though, they return floats:
    
        >>> 32 / 4
        8.0
    
    However, Python 3 has an explicit integer division operator:
    
        >>> 32 // 4
        8
    
    That operator exists on Python >= 2.2, so let's use it everywhere to
    make the scripts compatible with both Python 2 and 3.
    
    In addition, using __future__.division tells Python 2 to behave the same
    way as Python 3, which helps ensure the scripts produce the same output
    in both versions of Python.
    
    Signed-off-by: default avatarMathieu Bridon <bochecha@daitauha.fr>
    Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> (v2)
    Reviewed-by: default avatarDylan Baker <dylan@pnwbakers.com>
    9b6746b7