Skip to content

Commit

Permalink
Ensure significand remains an integer in Python3 json parser
Browse files Browse the repository at this point in the history
The / operation in Python 2 is "floor division" for int/long types
while in Python 3 is "true division". This means that the
significand can become a float with the existing code in Python 3.
This, in turn, can result in a parse of something like [1.10e1]
returning 11 in Python 2 and 11.0 in Python 3. Switching to the
// operator resolves this difference.

The JSON tests do not catch this difference because the built-in
serializer prints floats with the %.15g format which will convert
floats with no fractional part to an integer representation.

Signed-off-by: Terry Wilson <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
otherwiseguy authored and blp committed Jun 8, 2016
1 parent 2f22698 commit 2c362f1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python/ovs/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def __lex_finish_number(self):
significand *= 10
pow10 -= 1
while pow10 < 0 and significand % 10 == 0:
significand /= 10
significand //= 10
pow10 += 1
if (pow10 == 0 and
((not sign and significand < 2 ** 63) or
Expand Down

0 comments on commit 2c362f1

Please sign in to comment.