-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntOperations.py
More file actions
executable file
·87 lines (67 loc) · 1.73 KB
/
IntOperations.py
File metadata and controls
executable file
·87 lines (67 loc) · 1.73 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
85
86
87
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 09:45:28 2021
@author: maherme
"""
#%%
print(type(1 + 1))
print(type(2 * 3))
print(type(3 ** 6))
print(type(2/3))
print(type(10/2)) # Notice this is a float also
#%%
# Let's see the floor operator included in math
import math
print(math.floor(3.999999))
print(math.floor(-3.14))
print(math.floor(-3.0000001)) # Notice this is not rounding or truncating
# Notice the difference, this is due to limited precision in float:
print(math.floor(-3.0000000000001))
print(math.floor(-3.0000000000000001))
#%%
# Notice difference between positive and negative number:
a = 33
b = 16
print(a/b)
print(a//b)
print(math.floor(a/b))
a = -33
b = 16
print(a/b)
print(a//b)
print(math.floor(a/b))
print(math.trunc(a/b)) # Truncation is not the same that floor
#%%
# Notice difference between positive and negative number:
# Let's check this equation:
a = b*(a//b)+(a%b)
a = 13
b = 4
print("----- a > 0 and b > 0 -----")
print('{0}/{1} = {2}'.format(a, b, a/b))
print('{0}//{1} = {2}'.format(a, b, a//b))
print('{0}%{1} = {2}'.format(a, b, a%b))
print(a == b * (a//b) + (a%b))
a = -13
b = 4
print("----- a < 0 and b > 0 -----")
print('{0}/{1} = {2}'.format(a, b, a/b))
print('{0}//{1} = {2}'.format(a, b, a//b))
print('{0}%{1} = {2}'.format(a, b, a%b))
print(a == b * (a//b) + (a%b))
a = 13
b = -4
print("----- a > 0 and b < 0 -----")
print('{0}/{1} = {2}'.format(a, b, a/b))
print('{0}//{1} = {2}'.format(a, b, a//b))
print('{0}%{1} = {2}'.format(a, b, a%b))
print(a == b * (a//b) + (a%b))
a = -13
b = -4
print("----- a < 0 and b < 0 -----")
print('{0}/{1} = {2}'.format(a, b, a/b))
print('{0}//{1} = {2}'.format(a, b, a//b))
print('{0}%{1} = {2}'.format(a, b, a%b))
print(a == b * (a//b) + (a%b))
#%%