1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

mkicon.py: Work around Python 3's round() semantics.

Python 3 changed the built-in round() function to use round-to-even for
exact half-way cases.  While this eliminates a bias away from zero and
is thus a better choice in many cases, it's not what mkicon.py expected.

Shadow the built-in with an invocation of the decimal module instead:
this produces identical results for mkicon.py's purposes on both Python
2 and 3.
This commit is contained in:
Colin Watson 2019-08-30 13:40:44 +01:00 committed by Simon Tatham
parent a88eb54312
commit 30c7fec67e

View File

@ -2,6 +2,7 @@
from __future__ import division
import decimal
import math
# Python code which draws the PuTTY icon components at a range of
@ -15,6 +16,11 @@ import math
#
# - can we integrate the Mac icons into all this? Do we want to?
# Python 3 prefers round-to-even. Emulate Python 2's behaviour instead.
def round(number):
return float(
decimal.Decimal(number).to_integral(rounding=decimal.ROUND_HALF_UP))
def pixel(x, y, colour, canvas):
canvas[(int(x),int(y))] = colour