Lichen

Annotated tests/numbers.py

893:a13fc2cc28f0
2019-02-04 Paul Boddie Optimised __BOOL to test for integers and to return int values directly. For other value types, __VALUE need not be called once integers have been excluded, and so the attrvalue member can be accessed directly.
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@758 13
i = 2 ** 29
paul@758 14
print i                                 # 536870912
paul@758 15
print hex(i)                            # 0x20000000
paul@758 16
print oct(i)                            # 04000000000
paul@306 17
paul@758 18
j = -2 ** 29
paul@758 19
print j                                 # -536870912
paul@758 20
print hex(j)                            # -0x20000000
paul@758 21
print oct(j)                            # -05000000000
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@758 42
print ~j                                # 536870911
paul@307 43
print i & ~j                            # 0
paul@758 44
print i - 1 & ~j                        # 536870911
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