Lichen

tests/numbers.py

1029:b4d8e43dad4a
5 months ago Paul Boddie Merged changes from the trailing-data branch. value-replacement
     1 # -*- coding: ISO-8859-1 -*-     2      3 import sys     4      5 print "# sys.maxint:",     6 print sys.maxint     7 print "# sys.minint:",     8 print sys.minint     9     10 print "# sys.maxint + sys.minint:",    11 print sys.maxint + sys.minint    12     13 i = 2 ** 29    14 print i                                 # 536870912    15 print hex(i)                            # 0x20000000    16 print oct(i)                            # 04000000000    17     18 j = -2 ** 29    19 print j                                 # -536870912    20 print hex(j)                            # -0x20000000    21 print oct(j)                            # -04000000000    22     23 print i + j                             # 0    24     25 try:    26     print i - j    27 except OverflowError:    28     print "i - j: overflow occurred"    29     30 print i / i                             # 1    31 print i / j                             # -1    32 print j / j                             # 1    33 print j / i                             # -1    34     35 try:    36     print i * j    37 except OverflowError:    38     print "i * j: overflow occurred"    39     40 print i - i                             # 0    41 print j - j                             # 0    42 print ~j                                # 536870911    43 print i & ~j                            # 0    44 print i - 1 & ~j                        # 536870911    45     46 print hex(31)                           # 0x1f    47 print oct(31)                           # 037    48     49 print "# hash(sys.maxint):",    50 print hash(sys.maxint)    51     52 print "# hash((sys.maxint, 0)):",    53 print hash((sys.maxint, 0))    54     55 print "# hash((sys.maxint - 1, 0)):",    56 print hash((sys.maxint - 1, 0))    57     58 # Floating point numbers.    59     60 i = 2.0 ** 29    61 print i                                 # 536870912.0    62 j = -2.0 ** 29    63 print j                                 # -536870912.0    64 print i + j                             # 0    65 print i - j                             # -1073741824.0    66 print i * i                             # 2.8823037615171174e+17    67     68 try:    69     print i ** i    70 except OverflowError:    71     print "i ** i: overflow occurred"    72     73 # Test combining numbers with strings.    74     75 s = "Number is " + str(123)    76 s2 = "??? -> " + str(123)    77 print s.__class__    78 print s2.__class__    79 print s    80 print s2    81     82 sys.stdout.encoding = "UTF-8"    83 print s2