Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_float.HexFloatTestCase Class Reference

List of all members.

Public Member Functions

def identical
def test_ends
def test_invalid_inputs
def test_whitespace
def test_from_hex
def test_roundtrip

Static Public Attributes

tuple MAX = fromHex('0x.fffffffffffff8p+1024')
tuple MIN = fromHex('0x1p-1022')
tuple TINY = fromHex('0x0.0000000000001p-1022')
tuple EPS = fromHex('0x0.0000000000001p0')

Detailed Description

Definition at line 869 of file test_float.py.


Member Function Documentation

def test.test_float.HexFloatTestCase.identical (   self,
  x,
  y 
)

Definition at line 875 of file test_float.py.

00875 
00876     def identical(self, x, y):
00877         # check that floats x and y are identical, or that both
00878         # are NaNs
00879         if isnan(x) or isnan(y):
00880             if isnan(x) == isnan(y):
00881                 return
00882         elif x == y and (x != 0.0 or copysign(1.0, x) == copysign(1.0, y)):
00883             return
00884         self.fail('%r not identical to %r' % (x, y))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 885 of file test_float.py.

00885 
00886     def test_ends(self):
00887         self.identical(self.MIN, ldexp(1.0, -1022))
00888         self.identical(self.TINY, ldexp(1.0, -1074))
00889         self.identical(self.EPS, ldexp(1.0, -52))
00890         self.identical(self.MAX, 2.*(ldexp(1.0, 1023) - ldexp(1.0, 970)))

Here is the call graph for this function:

Definition at line 981 of file test_float.py.

00981 
00982     def test_from_hex(self):
00983         MIN = self.MIN;
00984         MAX = self.MAX;
00985         TINY = self.TINY;
00986         EPS = self.EPS;
00987 
00988         # two spellings of infinity, with optional signs; case-insensitive
00989         self.identical(fromHex('inf'), INF)
00990         self.identical(fromHex('+Inf'), INF)
00991         self.identical(fromHex('-INF'), -INF)
00992         self.identical(fromHex('iNf'), INF)
00993         self.identical(fromHex('Infinity'), INF)
00994         self.identical(fromHex('+INFINITY'), INF)
00995         self.identical(fromHex('-infinity'), -INF)
00996         self.identical(fromHex('-iNFiNitY'), -INF)
00997 
00998         # nans with optional sign; case insensitive
00999         self.identical(fromHex('nan'), NAN)
01000         self.identical(fromHex('+NaN'), NAN)
01001         self.identical(fromHex('-NaN'), NAN)
01002         self.identical(fromHex('-nAN'), NAN)
01003 
01004         # variations in input format
01005         self.identical(fromHex('1'), 1.0)
01006         self.identical(fromHex('+1'), 1.0)
01007         self.identical(fromHex('1.'), 1.0)
01008         self.identical(fromHex('1.0'), 1.0)
01009         self.identical(fromHex('1.0p0'), 1.0)
01010         self.identical(fromHex('01'), 1.0)
01011         self.identical(fromHex('01.'), 1.0)
01012         self.identical(fromHex('0x1'), 1.0)
01013         self.identical(fromHex('0x1.'), 1.0)
01014         self.identical(fromHex('0x1.0'), 1.0)
01015         self.identical(fromHex('+0x1.0'), 1.0)
01016         self.identical(fromHex('0x1p0'), 1.0)
01017         self.identical(fromHex('0X1p0'), 1.0)
01018         self.identical(fromHex('0X1P0'), 1.0)
01019         self.identical(fromHex('0x1P0'), 1.0)
01020         self.identical(fromHex('0x1.p0'), 1.0)
01021         self.identical(fromHex('0x1.0p0'), 1.0)
01022         self.identical(fromHex('0x.1p4'), 1.0)
01023         self.identical(fromHex('0x.1p04'), 1.0)
01024         self.identical(fromHex('0x.1p004'), 1.0)
01025         self.identical(fromHex('0x1p+0'), 1.0)
01026         self.identical(fromHex('0x1P-0'), 1.0)
01027         self.identical(fromHex('+0x1p0'), 1.0)
01028         self.identical(fromHex('0x01p0'), 1.0)
01029         self.identical(fromHex('0x1p00'), 1.0)
01030         self.identical(fromHex(' 0x1p0 '), 1.0)
01031         self.identical(fromHex('\n 0x1p0'), 1.0)
01032         self.identical(fromHex('0x1p0 \t'), 1.0)
01033         self.identical(fromHex('0xap0'), 10.0)
01034         self.identical(fromHex('0xAp0'), 10.0)
01035         self.identical(fromHex('0xaP0'), 10.0)
01036         self.identical(fromHex('0xAP0'), 10.0)
01037         self.identical(fromHex('0xbep0'), 190.0)
01038         self.identical(fromHex('0xBep0'), 190.0)
01039         self.identical(fromHex('0xbEp0'), 190.0)
01040         self.identical(fromHex('0XBE0P-4'), 190.0)
01041         self.identical(fromHex('0xBEp0'), 190.0)
01042         self.identical(fromHex('0xB.Ep4'), 190.0)
01043         self.identical(fromHex('0x.BEp8'), 190.0)
01044         self.identical(fromHex('0x.0BEp12'), 190.0)
01045 
01046         # moving the point around
01047         pi = fromHex('0x1.921fb54442d18p1')
01048         self.identical(fromHex('0x.006487ed5110b46p11'), pi)
01049         self.identical(fromHex('0x.00c90fdaa22168cp10'), pi)
01050         self.identical(fromHex('0x.01921fb54442d18p9'), pi)
01051         self.identical(fromHex('0x.03243f6a8885a3p8'), pi)
01052         self.identical(fromHex('0x.06487ed5110b46p7'), pi)
01053         self.identical(fromHex('0x.0c90fdaa22168cp6'), pi)
01054         self.identical(fromHex('0x.1921fb54442d18p5'), pi)
01055         self.identical(fromHex('0x.3243f6a8885a3p4'), pi)
01056         self.identical(fromHex('0x.6487ed5110b46p3'), pi)
01057         self.identical(fromHex('0x.c90fdaa22168cp2'), pi)
01058         self.identical(fromHex('0x1.921fb54442d18p1'), pi)
01059         self.identical(fromHex('0x3.243f6a8885a3p0'), pi)
01060         self.identical(fromHex('0x6.487ed5110b46p-1'), pi)
01061         self.identical(fromHex('0xc.90fdaa22168cp-2'), pi)
01062         self.identical(fromHex('0x19.21fb54442d18p-3'), pi)
01063         self.identical(fromHex('0x32.43f6a8885a3p-4'), pi)
01064         self.identical(fromHex('0x64.87ed5110b46p-5'), pi)
01065         self.identical(fromHex('0xc9.0fdaa22168cp-6'), pi)
01066         self.identical(fromHex('0x192.1fb54442d18p-7'), pi)
01067         self.identical(fromHex('0x324.3f6a8885a3p-8'), pi)
01068         self.identical(fromHex('0x648.7ed5110b46p-9'), pi)
01069         self.identical(fromHex('0xc90.fdaa22168cp-10'), pi)
01070         self.identical(fromHex('0x1921.fb54442d18p-11'), pi)
01071         # ...
01072         self.identical(fromHex('0x1921fb54442d1.8p-47'), pi)
01073         self.identical(fromHex('0x3243f6a8885a3p-48'), pi)
01074         self.identical(fromHex('0x6487ed5110b46p-49'), pi)
01075         self.identical(fromHex('0xc90fdaa22168cp-50'), pi)
01076         self.identical(fromHex('0x1921fb54442d18p-51'), pi)
01077         self.identical(fromHex('0x3243f6a8885a30p-52'), pi)
01078         self.identical(fromHex('0x6487ed5110b460p-53'), pi)
01079         self.identical(fromHex('0xc90fdaa22168c0p-54'), pi)
01080         self.identical(fromHex('0x1921fb54442d180p-55'), pi)
01081 
01082 
01083         # results that should overflow...
01084         self.assertRaises(OverflowError, fromHex, '-0x1p1024')
01085         self.assertRaises(OverflowError, fromHex, '0x1p+1025')
01086         self.assertRaises(OverflowError, fromHex, '+0X1p1030')
01087         self.assertRaises(OverflowError, fromHex, '-0x1p+1100')
01088         self.assertRaises(OverflowError, fromHex, '0X1p123456789123456789')
01089         self.assertRaises(OverflowError, fromHex, '+0X.8p+1025')
01090         self.assertRaises(OverflowError, fromHex, '+0x0.8p1025')
01091         self.assertRaises(OverflowError, fromHex, '-0x0.4p1026')
01092         self.assertRaises(OverflowError, fromHex, '0X2p+1023')
01093         self.assertRaises(OverflowError, fromHex, '0x2.p1023')
01094         self.assertRaises(OverflowError, fromHex, '-0x2.0p+1023')
01095         self.assertRaises(OverflowError, fromHex, '+0X4p+1022')
01096         self.assertRaises(OverflowError, fromHex, '0x1.ffffffffffffffp+1023')
01097         self.assertRaises(OverflowError, fromHex, '-0X1.fffffffffffff9p1023')
01098         self.assertRaises(OverflowError, fromHex, '0X1.fffffffffffff8p1023')
01099         self.assertRaises(OverflowError, fromHex, '+0x3.fffffffffffffp1022')
01100         self.assertRaises(OverflowError, fromHex, '0x3fffffffffffffp+970')
01101         self.assertRaises(OverflowError, fromHex, '0x10000000000000000p960')
01102         self.assertRaises(OverflowError, fromHex, '-0Xffffffffffffffffp960')
01103 
01104         # ...and those that round to +-max float
01105         self.identical(fromHex('+0x1.fffffffffffffp+1023'), MAX)
01106         self.identical(fromHex('-0X1.fffffffffffff7p1023'), -MAX)
01107         self.identical(fromHex('0X1.fffffffffffff7fffffffffffffp1023'), MAX)
01108 
01109         # zeros
01110         self.identical(fromHex('0x0p0'), 0.0)
01111         self.identical(fromHex('0x0p1000'), 0.0)
01112         self.identical(fromHex('-0x0p1023'), -0.0)
01113         self.identical(fromHex('0X0p1024'), 0.0)
01114         self.identical(fromHex('-0x0p1025'), -0.0)
01115         self.identical(fromHex('0X0p2000'), 0.0)
01116         self.identical(fromHex('0x0p123456789123456789'), 0.0)
01117         self.identical(fromHex('-0X0p-0'), -0.0)
01118         self.identical(fromHex('-0X0p-1000'), -0.0)
01119         self.identical(fromHex('0x0p-1023'), 0.0)
01120         self.identical(fromHex('-0X0p-1024'), -0.0)
01121         self.identical(fromHex('-0x0p-1025'), -0.0)
01122         self.identical(fromHex('-0x0p-1072'), -0.0)
01123         self.identical(fromHex('0X0p-1073'), 0.0)
01124         self.identical(fromHex('-0x0p-1074'), -0.0)
01125         self.identical(fromHex('0x0p-1075'), 0.0)
01126         self.identical(fromHex('0X0p-1076'), 0.0)
01127         self.identical(fromHex('-0X0p-2000'), -0.0)
01128         self.identical(fromHex('-0x0p-123456789123456789'), -0.0)
01129 
01130         # values that should underflow to 0
01131         self.identical(fromHex('0X1p-1075'), 0.0)
01132         self.identical(fromHex('-0X1p-1075'), -0.0)
01133         self.identical(fromHex('-0x1p-123456789123456789'), -0.0)
01134         self.identical(fromHex('0x1.00000000000000001p-1075'), TINY)
01135         self.identical(fromHex('-0x1.1p-1075'), -TINY)
01136         self.identical(fromHex('0x1.fffffffffffffffffp-1075'), TINY)
01137 
01138         # check round-half-even is working correctly near 0 ...
01139         self.identical(fromHex('0x1p-1076'), 0.0)
01140         self.identical(fromHex('0X2p-1076'), 0.0)
01141         self.identical(fromHex('0X3p-1076'), TINY)
01142         self.identical(fromHex('0x4p-1076'), TINY)
01143         self.identical(fromHex('0X5p-1076'), TINY)
01144         self.identical(fromHex('0X6p-1076'), 2*TINY)
01145         self.identical(fromHex('0x7p-1076'), 2*TINY)
01146         self.identical(fromHex('0X8p-1076'), 2*TINY)
01147         self.identical(fromHex('0X9p-1076'), 2*TINY)
01148         self.identical(fromHex('0xap-1076'), 2*TINY)
01149         self.identical(fromHex('0Xbp-1076'), 3*TINY)
01150         self.identical(fromHex('0xcp-1076'), 3*TINY)
01151         self.identical(fromHex('0Xdp-1076'), 3*TINY)
01152         self.identical(fromHex('0Xep-1076'), 4*TINY)
01153         self.identical(fromHex('0xfp-1076'), 4*TINY)
01154         self.identical(fromHex('0x10p-1076'), 4*TINY)
01155         self.identical(fromHex('-0x1p-1076'), -0.0)
01156         self.identical(fromHex('-0X2p-1076'), -0.0)
01157         self.identical(fromHex('-0x3p-1076'), -TINY)
01158         self.identical(fromHex('-0X4p-1076'), -TINY)
01159         self.identical(fromHex('-0x5p-1076'), -TINY)
01160         self.identical(fromHex('-0x6p-1076'), -2*TINY)
01161         self.identical(fromHex('-0X7p-1076'), -2*TINY)
01162         self.identical(fromHex('-0X8p-1076'), -2*TINY)
01163         self.identical(fromHex('-0X9p-1076'), -2*TINY)
01164         self.identical(fromHex('-0Xap-1076'), -2*TINY)
01165         self.identical(fromHex('-0xbp-1076'), -3*TINY)
01166         self.identical(fromHex('-0xcp-1076'), -3*TINY)
01167         self.identical(fromHex('-0Xdp-1076'), -3*TINY)
01168         self.identical(fromHex('-0xep-1076'), -4*TINY)
01169         self.identical(fromHex('-0Xfp-1076'), -4*TINY)
01170         self.identical(fromHex('-0X10p-1076'), -4*TINY)
01171 
01172         # ... and near MIN ...
01173         self.identical(fromHex('0x0.ffffffffffffd6p-1022'), MIN-3*TINY)
01174         self.identical(fromHex('0x0.ffffffffffffd8p-1022'), MIN-2*TINY)
01175         self.identical(fromHex('0x0.ffffffffffffdap-1022'), MIN-2*TINY)
01176         self.identical(fromHex('0x0.ffffffffffffdcp-1022'), MIN-2*TINY)
01177         self.identical(fromHex('0x0.ffffffffffffdep-1022'), MIN-2*TINY)
01178         self.identical(fromHex('0x0.ffffffffffffe0p-1022'), MIN-2*TINY)
01179         self.identical(fromHex('0x0.ffffffffffffe2p-1022'), MIN-2*TINY)
01180         self.identical(fromHex('0x0.ffffffffffffe4p-1022'), MIN-2*TINY)
01181         self.identical(fromHex('0x0.ffffffffffffe6p-1022'), MIN-2*TINY)
01182         self.identical(fromHex('0x0.ffffffffffffe8p-1022'), MIN-2*TINY)
01183         self.identical(fromHex('0x0.ffffffffffffeap-1022'), MIN-TINY)
01184         self.identical(fromHex('0x0.ffffffffffffecp-1022'), MIN-TINY)
01185         self.identical(fromHex('0x0.ffffffffffffeep-1022'), MIN-TINY)
01186         self.identical(fromHex('0x0.fffffffffffff0p-1022'), MIN-TINY)
01187         self.identical(fromHex('0x0.fffffffffffff2p-1022'), MIN-TINY)
01188         self.identical(fromHex('0x0.fffffffffffff4p-1022'), MIN-TINY)
01189         self.identical(fromHex('0x0.fffffffffffff6p-1022'), MIN-TINY)
01190         self.identical(fromHex('0x0.fffffffffffff8p-1022'), MIN)
01191         self.identical(fromHex('0x0.fffffffffffffap-1022'), MIN)
01192         self.identical(fromHex('0x0.fffffffffffffcp-1022'), MIN)
01193         self.identical(fromHex('0x0.fffffffffffffep-1022'), MIN)
01194         self.identical(fromHex('0x1.00000000000000p-1022'), MIN)
01195         self.identical(fromHex('0x1.00000000000002p-1022'), MIN)
01196         self.identical(fromHex('0x1.00000000000004p-1022'), MIN)
01197         self.identical(fromHex('0x1.00000000000006p-1022'), MIN)
01198         self.identical(fromHex('0x1.00000000000008p-1022'), MIN)
01199         self.identical(fromHex('0x1.0000000000000ap-1022'), MIN+TINY)
01200         self.identical(fromHex('0x1.0000000000000cp-1022'), MIN+TINY)
01201         self.identical(fromHex('0x1.0000000000000ep-1022'), MIN+TINY)
01202         self.identical(fromHex('0x1.00000000000010p-1022'), MIN+TINY)
01203         self.identical(fromHex('0x1.00000000000012p-1022'), MIN+TINY)
01204         self.identical(fromHex('0x1.00000000000014p-1022'), MIN+TINY)
01205         self.identical(fromHex('0x1.00000000000016p-1022'), MIN+TINY)
01206         self.identical(fromHex('0x1.00000000000018p-1022'), MIN+2*TINY)
01207 
01208         # ... and near 1.0.
01209         self.identical(fromHex('0x0.fffffffffffff0p0'), 1.0-EPS)
01210         self.identical(fromHex('0x0.fffffffffffff1p0'), 1.0-EPS)
01211         self.identical(fromHex('0X0.fffffffffffff2p0'), 1.0-EPS)
01212         self.identical(fromHex('0x0.fffffffffffff3p0'), 1.0-EPS)
01213         self.identical(fromHex('0X0.fffffffffffff4p0'), 1.0-EPS)
01214         self.identical(fromHex('0X0.fffffffffffff5p0'), 1.0-EPS/2)
01215         self.identical(fromHex('0X0.fffffffffffff6p0'), 1.0-EPS/2)
01216         self.identical(fromHex('0x0.fffffffffffff7p0'), 1.0-EPS/2)
01217         self.identical(fromHex('0x0.fffffffffffff8p0'), 1.0-EPS/2)
01218         self.identical(fromHex('0X0.fffffffffffff9p0'), 1.0-EPS/2)
01219         self.identical(fromHex('0X0.fffffffffffffap0'), 1.0-EPS/2)
01220         self.identical(fromHex('0x0.fffffffffffffbp0'), 1.0-EPS/2)
01221         self.identical(fromHex('0X0.fffffffffffffcp0'), 1.0)
01222         self.identical(fromHex('0x0.fffffffffffffdp0'), 1.0)
01223         self.identical(fromHex('0X0.fffffffffffffep0'), 1.0)
01224         self.identical(fromHex('0x0.ffffffffffffffp0'), 1.0)
01225         self.identical(fromHex('0X1.00000000000000p0'), 1.0)
01226         self.identical(fromHex('0X1.00000000000001p0'), 1.0)
01227         self.identical(fromHex('0x1.00000000000002p0'), 1.0)
01228         self.identical(fromHex('0X1.00000000000003p0'), 1.0)
01229         self.identical(fromHex('0x1.00000000000004p0'), 1.0)
01230         self.identical(fromHex('0X1.00000000000005p0'), 1.0)
01231         self.identical(fromHex('0X1.00000000000006p0'), 1.0)
01232         self.identical(fromHex('0X1.00000000000007p0'), 1.0)
01233         self.identical(fromHex('0x1.00000000000007ffffffffffffffffffffp0'),
01234                        1.0)
01235         self.identical(fromHex('0x1.00000000000008p0'), 1.0)
01236         self.identical(fromHex('0x1.00000000000008000000000000000001p0'),
01237                        1+EPS)
01238         self.identical(fromHex('0X1.00000000000009p0'), 1.0+EPS)
01239         self.identical(fromHex('0x1.0000000000000ap0'), 1.0+EPS)
01240         self.identical(fromHex('0x1.0000000000000bp0'), 1.0+EPS)
01241         self.identical(fromHex('0X1.0000000000000cp0'), 1.0+EPS)
01242         self.identical(fromHex('0x1.0000000000000dp0'), 1.0+EPS)
01243         self.identical(fromHex('0x1.0000000000000ep0'), 1.0+EPS)
01244         self.identical(fromHex('0X1.0000000000000fp0'), 1.0+EPS)
01245         self.identical(fromHex('0x1.00000000000010p0'), 1.0+EPS)
01246         self.identical(fromHex('0X1.00000000000011p0'), 1.0+EPS)
01247         self.identical(fromHex('0x1.00000000000012p0'), 1.0+EPS)
01248         self.identical(fromHex('0X1.00000000000013p0'), 1.0+EPS)
01249         self.identical(fromHex('0X1.00000000000014p0'), 1.0+EPS)
01250         self.identical(fromHex('0x1.00000000000015p0'), 1.0+EPS)
01251         self.identical(fromHex('0x1.00000000000016p0'), 1.0+EPS)
01252         self.identical(fromHex('0X1.00000000000017p0'), 1.0+EPS)
01253         self.identical(fromHex('0x1.00000000000017ffffffffffffffffffffp0'),
01254                        1.0+EPS)
01255         self.identical(fromHex('0x1.00000000000018p0'), 1.0+2*EPS)
01256         self.identical(fromHex('0X1.00000000000018000000000000000001p0'),
01257                        1.0+2*EPS)
01258         self.identical(fromHex('0x1.00000000000019p0'), 1.0+2*EPS)
01259         self.identical(fromHex('0X1.0000000000001ap0'), 1.0+2*EPS)
01260         self.identical(fromHex('0X1.0000000000001bp0'), 1.0+2*EPS)
01261         self.identical(fromHex('0x1.0000000000001cp0'), 1.0+2*EPS)
01262         self.identical(fromHex('0x1.0000000000001dp0'), 1.0+2*EPS)
01263         self.identical(fromHex('0x1.0000000000001ep0'), 1.0+2*EPS)
01264         self.identical(fromHex('0X1.0000000000001fp0'), 1.0+2*EPS)
01265         self.identical(fromHex('0x1.00000000000020p0'), 1.0+2*EPS)

Here is the call graph for this function:

Definition at line 891 of file test_float.py.

00891 
00892     def test_invalid_inputs(self):
00893         invalid_inputs = [
00894             'infi',   # misspelt infinities and nans
00895             '-Infinit',
00896             '++inf',
00897             '-+Inf',
00898             '--nan',
00899             '+-NaN',
00900             'snan',
00901             'NaNs',
00902             'nna',
00903             'an',
00904             'nf',
00905             'nfinity',
00906             'inity',
00907             'iinity',
00908             '0xnan',
00909             '',
00910             ' ',
00911             'x1.0p0',
00912             '0xX1.0p0',
00913             '+ 0x1.0p0', # internal whitespace
00914             '- 0x1.0p0',
00915             '0 x1.0p0',
00916             '0x 1.0p0',
00917             '0x1 2.0p0',
00918             '+0x1 .0p0',
00919             '0x1. 0p0',
00920             '-0x1.0 1p0',
00921             '-0x1.0 p0',
00922             '+0x1.0p +0',
00923             '0x1.0p -0',
00924             '0x1.0p 0',
00925             '+0x1.0p+ 0',
00926             '-0x1.0p- 0',
00927             '++0x1.0p-0', # double signs
00928             '--0x1.0p0',
00929             '+-0x1.0p+0',
00930             '-+0x1.0p0',
00931             '0x1.0p++0',
00932             '+0x1.0p+-0',
00933             '-0x1.0p-+0',
00934             '0x1.0p--0',
00935             '0x1.0.p0',
00936             '0x.p0', # no hex digits before or after point
00937             '0x1,p0', # wrong decimal point character
00938             '0x1pa',
00939             '0x1p\uff10',  # fullwidth Unicode digits
00940             '\uff10x1p0',
00941             '0x\uff11p0',
00942             '0x1.\uff10p0',
00943             '0x1p0 \n 0x2p0',
00944             '0x1p0\0 0x1p0',  # embedded null byte is not end of string
00945             ]
00946         for x in invalid_inputs:
00947             try:
00948                 result = fromHex(x)
00949             except ValueError:
00950                 pass
00951             else:
00952                 self.fail('Expected float.fromhex(%r) to raise ValueError; '
00953                           'got %r instead' % (x, result))
00954 

Here is the call graph for this function:

Definition at line 1266 of file test_float.py.

01266 
01267     def test_roundtrip(self):
01268         def roundtrip(x):
01269             return fromHex(toHex(x))
01270 
01271         for x in [NAN, INF, self.MAX, self.MIN, self.MIN-self.TINY, self.TINY, 0.0]:
01272             self.identical(x, roundtrip(x))
01273             self.identical(-x, roundtrip(-x))
01274 
01275         # fromHex(toHex(x)) should exactly recover x, for any non-NaN float x.
01276         import random
01277         for i in range(10000):
01278             e = random.randrange(-1200, 1200)
01279             m = random.random()
01280             s = random.choice([1.0, -1.0])
01281             try:
01282                 x = s*ldexp(m, e)
01283             except OverflowError:
01284                 pass
01285             else:
01286                 self.identical(x, fromHex(toHex(x)))
01287 

Here is the call graph for this function:

Definition at line 955 of file test_float.py.

00955 
00956     def test_whitespace(self):
00957         value_pairs = [
00958             ('inf', INF),
00959             ('-Infinity', -INF),
00960             ('nan', NAN),
00961             ('1.0', 1.0),
00962             ('-0x.2', -0.125),
00963             ('-0.0', -0.0)
00964             ]
00965         whitespace = [
00966             '',
00967             ' ',
00968             '\t',
00969             '\n',
00970             '\n \t',
00971             '\f',
00972             '\v',
00973             '\r'
00974             ]
00975         for inp, expected in value_pairs:
00976             for lead in whitespace:
00977                 for trail in whitespace:
00978                     got = fromHex(lead + inp + trail)
00979                     self.identical(got, expected)
00980 

Here is the call graph for this function:


Member Data Documentation

tuple test.test_float.HexFloatTestCase.EPS = fromHex('0x0.0000000000001p0') [static]

Definition at line 873 of file test_float.py.

tuple test.test_float.HexFloatTestCase.MAX = fromHex('0x.fffffffffffff8p+1024') [static]

Definition at line 870 of file test_float.py.

tuple test.test_float.HexFloatTestCase.MIN = fromHex('0x1p-1022') [static]

Definition at line 871 of file test_float.py.

tuple test.test_float.HexFloatTestCase.TINY = fromHex('0x0.0000000000001p-1022') [static]

Definition at line 872 of file test_float.py.


The documentation for this class was generated from the following file: