Lichen

Annotated tests/numbers.py

627:05ad7964265c
2017-02-27 Paul Boddie Merged convenience macro changes.
paul@472 1
# -*- coding: ISO-8859-1 -*-
paul@472 2
paul@309 3
import sys
paul@309 4
paul@494 5
print "# sys.maxint:",
paul@309 6
print sys.maxint
paul@494 7
print "# sys.minint:",
paul@309 8
print sys.minint
paul@309 9
paul@494 10
print "# sys.maxint + sys.minint:",
paul@309 11
print sys.maxint + sys.minint
paul@309 12
paul@306 13
i = 2 ** 30
paul@307 14
print i                                 # 1073741824
paul@374 15
print hex(i)                            # 0x40000000
paul@374 16
print oct(i)                            # 010000000000
paul@306 17
paul@306 18
j = -2 ** 30
paul@307 19
print j                                 # -1073741824
paul@374 20
print hex(j)                            # -0x40000000
paul@374 21
print oct(j)                            # -010000000000
paul@306 22
paul@307 23
print i + j                             # 0
paul@306 24
paul@306 25
try:
paul@306 26
    print i - j
paul@306 27
except OverflowError:
paul@306 28
    print "i - j: overflow occurred"
paul@306 29
paul@307 30
print i / i                             # 1
paul@307 31
print i / j                             # -1
paul@307 32
print j / j                             # 1
paul@307 33
print j / i                             # -1
paul@306 34
paul@306 35
try:
paul@306 36
    print i * j
paul@306 37
except OverflowError:
paul@306 38
    print "i * j: overflow occurred"
paul@307 39
paul@307 40
print i - i                             # 0
paul@307 41
print j - j                             # 0
paul@307 42
print ~j                                # 1073741823
paul@307 43
print i & ~j                            # 0
paul@307 44
print i - 1 & ~j                        # 1073741823
paul@374 45
paul@374 46
print hex(31)                           # 0x1f
paul@374 47
print oct(31)                           # 037
paul@461 48
paul@494 49
print "# hash(sys.maxint):",
paul@461 50
print hash(sys.maxint)
paul@461 51
paul@494 52
print "# hash((sys.maxint, 0)):",
paul@461 53
print hash((sys.maxint, 0))
paul@461 54
paul@494 55
print "# hash((sys.maxint - 1, 0)):",
paul@461 56
print hash((sys.maxint - 1, 0))
paul@472 57
paul@472 58
# Test combining numbers with strings.
paul@472 59
paul@472 60
s = "Number is " + str(123)
paul@472 61
s2 = "??? -> " + str(123)
paul@472 62
print s.__class__
paul@472 63
print s2.__class__
paul@472 64
print s
paul@472 65
print s2
paul@472 66
paul@472 67
sys.stdout.encoding = "UTF-8"
paul@472 68
print s2