Kaydet (Commit) 33e4a98a authored tarafından Christian Heimes's avatar Christian Heimes

Replace more float hacks with correct math functions

üst 342c095b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
""" """
import re import re
import math
try: try:
from _json import encode_basestring_ascii as c_encode_basestring_ascii from _json import encode_basestring_ascii as c_encode_basestring_ascii
...@@ -25,20 +26,19 @@ ESCAPE_DCT = { ...@@ -25,20 +26,19 @@ ESCAPE_DCT = {
for i in range(0x20): for i in range(0x20):
ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i)) ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
# Assume this produces an infinity on all machines (probably not guaranteed)
INFINITY = float('1e66666')
FLOAT_REPR = repr FLOAT_REPR = repr
def floatstr(o, allow_nan=True): def floatstr(o, allow_nan=True):
# Check for specials. Note that this type of test is processor- and/or # Check for specials. Note that this type of test is processor- and/or
# platform-specific, so do tests which don't depend on the internals. # platform-specific, so do tests which don't depend on the internals.
if o != o: if math.isnan(o):
text = 'NaN' text = 'NaN'
elif o == INFINITY: elif math.isinf(o):
text = 'Infinity' if math.copysign(1., o) == 1.:
elif o == -INFINITY: text = 'Infinity'
text = '-Infinity' else:
text = '-Infinity'
else: else:
return FLOAT_REPR(o) return FLOAT_REPR(o)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment