-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator_math.py
More file actions
84 lines (74 loc) · 1.53 KB
/
Copy pathoperator_math.py
File metadata and controls
84 lines (74 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2008 Doug Hellmann All rights reserved.
#
"""
"""
__version__ = "$Id$"
#end_pymotw_header
from operator import *
a = -1
b = 5.0
c = 2
d = 6
print 'a =', a
print 'b =', b
print 'c =', c
print 'd =', d
# a = -1
# b = 5.0
# c = 2
# d = 6
print '\nPositive/Negative:'
print 'abs(a):', abs(a)
print 'neg(a):', neg(a)
print 'neg(b):', neg(b)
print 'pos(a):', pos(a)
print 'pos(b):', pos(b)
#
# Positive/Negative:
# abs(a): 1
# neg(a): 1
# neg(b): -5.0
# pos(a): -1
# pos(b): 5.0
#
print '\nArithmetic:'
print 'add(a, b) :', add(a, b)
print 'div(a, b) :', div(a, b)
print 'div(d, c) :', div(d, c)
print 'floordiv(a, b):', floordiv(a, b)
print 'floordiv(d, c):', floordiv(d, c)
print 'mod(a, b) :', mod(a, b)
print 'mul(a, b) :', mul(a, b)
print 'pow(c, d) :', pow(c, d)
print 'sub(b, a) :', sub(b, a)
print 'truediv(a, b) :', truediv(a, b)
print 'truediv(d, c) :', truediv(d, c)
# Arithmetic:
# add(a, b) : 4.0
# div(a, b) : -0.2
# div(d, c) : 3
# floordiv(a, b): -1.0
# floordiv(d, c): 3
# mod(a, b) : 4.0
# mul(a, b) : -5.0
# pow(c, d) : 64
# sub(b, a) : 6.0
# truediv(a, b) : -0.2
# truediv(d, c) : 3.0
print '\nBitwise:'
print 'and_(c, d) :', and_(c, d)
print 'invert(c) :', invert(c)
print 'lshift(c, d):', lshift(c, d)
print 'or_(c, d) :', or_(c, d)
print 'rshift(d, c):', rshift(d, c)
print 'xor(c, d) :', xor(c, d)
# Bitwise:
# and_(c, d) : 2
# invert(c) : -3
# lshift(c, d): 128
# or_(c, d) : 6
# rshift(d, c): 1
# xor(c, d) : 4