-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminiprob.py
More file actions
53 lines (33 loc) · 919 Bytes
/
Copy pathminiprob.py
File metadata and controls
53 lines (33 loc) · 919 Bytes
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
# #1 Swapping values with out temp variables
# a = 50
# b = 70
# a = a+b #120
# b = a-b #50
# a = a-b #70
# print("After swapping: a = ",a ,"b = ",b)
# Key Points:
# Floating-Point Representation:
# Numbers like 0.1, 0.2, and 0.3 cannot be represented exactly in binary. Instead, they are stored as approximations, which leads to rounding errors.
# These errors occur because some decimal fractions cannot be represented as finite binary fractions (similar to how 1/3 in decimal is a repeating fraction: 0.333...).
# Languages with Similar Behavior: The issue of 0.1 + 0.2 != 0.3 happens in most programming languages, including but not limited to:
# C
# C++
# Java
# JavaScript
# C#
# Ruby
# Go
# PHP
# Swift
if(0.1+0.2 == 0.3):
print('True')
else:
print('False')
if(0.1+0.1 == 0.2):
print('True')
else:
print('False')
if(0.1+0.3 == 0.4):
print('True')
else:
print('False')