Changeset 2438
- Timestamp:
- 06/01/09 09:45:19 (10 months ago)
- Location:
- pyamf/branches/remove-fpconst-564/pyamf
- Files:
-
- 1 added
- 2 modified
-
tests/test_platform.py (added)
-
tests/util.py (modified) (2 diffs)
-
util/__init__.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyamf/branches/remove-fpconst-564/pyamf/tests/util.py
r2432 r2438 13 13 import pyamf 14 14 from pyamf.util import BufferedByteStream, is_float_broken 15 16 PosInf = 1e300000 17 NegInf = -1e300000 18 NaN = PosInf / PosInf 15 19 16 20 … … 111 115 112 116 def isNaN(val): 113 if is_float_broken(): 114 import fpconst 115 116 return fpconst.isNaN(val) 117 else: 118 return str(float(val)) == str(1e300000/1e300000) 117 return str(float(val)) == str(NaN) 119 118 120 119 121 120 def isPosInf(val): 122 if is_float_broken(): 123 import fpconst 124 125 return fpconst.isPosInf(val) 126 else: 127 return val == 1e300000 121 return str(float(val)) == str(PosInf) 128 122 129 123 130 124 def isNegInf(val): 131 if is_float_broken(): 132 import fpconst 133 134 return fpconst.isNegInf(val) 135 else: 136 return val == -1e300000 125 return str(float(val)) == str(NegInf) 137 126 138 127 -
pyamf/branches/remove-fpconst-564/pyamf/util/__init__.py
r2432 r2438 21 21 except ImportError: 22 22 from StringIO import StringIO 23 23 24 24 25 xml_types = None … … 42 43 int_types = tuple(int_types) 43 44 str_types = tuple(str_types) 45 46 PosInf = 1e300000 47 NegInf = -1e300000 48 # we do this instead of float('nan') because windows throws a wobbler. 49 NaN = PosInf / PosInf 44 50 45 51 … … 911 917 @rtype: C{bool} 912 918 """ 913 # we do this instead of float('nan') because windows throws a wobbler. 914 nan = 1e300000/1e300000 915 916 return str(nan) != str(struct.unpack("!d", '\xff\xf8\x00\x00\x00\x00\x00\x00')[0]) 919 global NaN 920 921 return str(NaN) != str(struct.unpack("!d", '\xff\xf8\x00\x00\x00\x00\x00\x00')[0]) 922 923 924 def isNaN(val): 925 return str(float(val)) == str(NaN) 926 927 928 def isPosInf(val): 929 return str(float(val)) == str(PosInf) 930 931 932 def isNegInf(val): 933 return str(float(val)) == str(NegInf) 917 934 918 935 … … 927 944 928 945 if is_float_broken(): 929 import fpconst930 931 946 def read_double_workaround(self): 947 global PosInf, NegInf, NaN 948 932 949 bytes = self.read(8) 933 950 934 951 if self._is_big_endian(): 935 952 if bytes == '\xff\xf8\x00\x00\x00\x00\x00\x00': 936 return fpconst.NaN953 return NaN 937 954 938 955 if bytes == '\xff\xf0\x00\x00\x00\x00\x00\x00': 939 return fpconst.NegInf956 return NegInf 940 957 941 958 if bytes == '\x7f\xf0\x00\x00\x00\x00\x00\x00': 942 return fpconst.PosInf959 return PosInf 943 960 else: 944 961 if bytes == '\x00\x00\x00\x00\x00\x00\xf8\xff': 945 return fpconst.NaN962 return NaN 946 963 947 964 if bytes == '\x00\x00\x00\x00\x00\x00\xf0\xff': 948 return fpconst.NegInf965 return NegInf 949 966 950 967 if bytes == '\x00\x00\x00\x00\x00\x00\xf0\x7f': 951 return fpconst.PosInf968 return PosInf 952 969 953 970 return struct.unpack("%sd" % self.endian, bytes)[0] … … 959 976 raise TypeError('expected a float (got:%r)' % (type(d),)) 960 977 961 if fpconst.isNaN(d):978 if isNaN(d): 962 979 if self._is_big_endian(): 963 980 self.write('\xff\xf8\x00\x00\x00\x00\x00\x00') 964 981 else: 965 982 self.write('\x00\x00\x00\x00\x00\x00\xf8\xff') 966 elif fpconst.isNegInf(d):983 elif isNegInf(d): 967 984 if self._is_big_endian(): 968 985 self.write('\xff\xf0\x00\x00\x00\x00\x00\x00') 969 986 else: 970 987 self.write('\x00\x00\x00\x00\x00\x00\xf0\xff') 971 elif fpconst.isPosInf(d):988 elif isPosInf(d): 972 989 if self._is_big_endian(): 973 990 self.write('\x7f\xf0\x00\x00\x00\x00\x00\x00') … … 980 997 DataTypeMixIn.write_double = write_double_workaround 981 998 write_double_workaround.old_func = x 999 982 1000 983 1001 try:
