OILS / mycpp / examples / test_arith_ops.py View on Github | oilshell.org

45 lines, 18 significant
1#!/usr/bin/env python2
2"""
3mycpp/examples/arith_ops.py
4"""
5from __future__ import print_function
6
7import os
8from mycpp.mylib import log
9
10
11def run_tests():
12 # type: () -> None
13
14 for i in xrange(8):
15 log("%d // 3 = %d", i, i // 3)
16
17 log('')
18
19 # SEMANTIC DIFFERENCE with negative numbers:
20 #
21 # - Python: -1 / 3 == -1 and
22 # -4 / 3 == -2
23 # it rounds toward negative infinity
24 # - C++: -1 / 3 == 0
25 # -4 / 3 == -1
26 # it rounds toward zero
27
28 # TODO: We could create a function like python_div() to make them identical?
29
30 if 0:
31 for i in xrange(8):
32 log("%d // 3 = %d", -i, -i // 3)
33
34
35def run_benchmarks():
36 # type: () -> None
37 pass
38
39
40if __name__ == '__main__':
41 if os.getenv('BENCHMARK'):
42 log('Benchmarking...')
43 run_benchmarks()
44 else:
45 run_tests()