diff options
author | Mathieu Bridon <[email protected]> | 2018-07-25 11:53:54 +0200 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2018-08-07 13:07:44 -0700 |
commit | 9b6746b7c0bef64be419c8cf2ecd916980e2718a (patch) | |
tree | 1c84ed2623ee06a682459cc5d1dcd3e662d04285 /src/gallium | |
parent | 3dc22381fa6ae6e5964908490f65e2903bd1b38d (diff) |
python: Use explicit integer divisions
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: Mathieu Bridon <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]> (v2)
Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/util/u_format_pack.py | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_parse.py | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 7a952a48b30..ad2e49281fb 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -36,7 +36,7 @@ ''' -from __future__ import print_function +from __future__ import division, print_function from u_format_parse import * @@ -240,7 +240,7 @@ def value_to_native(type, value): return truncate_mantissa(value, 23) return value if type.type == FIXED: - return int(value * (1 << (type.size/2))) + return int(value * (1 << (type.size // 2))) if not type.norm: return int(value) if type.type == UNSIGNED: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index c0456f6d159..d3874cd895b 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -29,6 +29,9 @@ ''' +from __future__ import division + + VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5) SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7) @@ -76,7 +79,7 @@ class Channel: if self.type == FLOAT: return VERY_LARGE if self.type == FIXED: - return (1 << (self.size/2)) - 1 + return (1 << (self.size // 2)) - 1 if self.norm: return 1 if self.type == UNSIGNED: @@ -90,7 +93,7 @@ class Channel: if self.type == FLOAT: return -VERY_LARGE if self.type == FIXED: - return -(1 << (self.size/2)) + return -(1 << (self.size // 2)) if self.type == UNSIGNED: return 0 if self.norm: |