/
inf_compare.py
109 lines (72 loc) · 1.73 KB
/
inf_compare.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import math
import numpy as np
print(1e1000)
# inf
print(1e100)
# 1e+100
print(1e1000 == float('inf'))
# True
print(1e100 == float('inf'))
# False
print(float('inf') == math.inf == np.inf)
# True
print(1e1000 == math.inf)
# True
print(1e100 == math.inf)
# False
print(float('inf') == float('inf') * 100)
# True
print(math.isinf(1e1000))
# True
print(math.isinf(1e100))
# False
print(math.isinf(-1e1000))
# True
print(np.isinf(1e1000))
# True
print(np.isinf(1e100))
# False
print(np.isinf(-1e1000))
# True
a_inf = np.array([1, np.inf, 3, -np.inf])
print(a_inf)
# [ 1. inf 3. -inf]
print(type(a_inf))
# <class 'numpy.ndarray'>
print(np.isinf(a_inf))
# [False True False True]
a_inf[np.isinf(a_inf)] = 0
print(a_inf)
# [1. 0. 3. 0.]
import sys
print(sys.float_info.max)
# 1.7976931348623157e+308
print(float('inf') > sys.float_info.max)
# True
print(-float('inf') < -sys.float_info.max)
# True
print(float('nan'))
# nan
print(type(float('nan')))
# <class 'float'>
print(float('inf') > float('nan'))
# False
print(float('inf') < float('nan'))
# False
print(float('inf') == float('nan'))
# False
print(float('inf') > 100)
# True
large_int = int(sys.float_info.max) * 10
print(large_int)
# 1797693134862315708145274237317043567980705675258449965989174768031572607800285387605895586327668781715404589535143824642343213268894641827684675467035375169860499105765512820762454900903893289440758685084551339423045832369032229481658085593321233482747978262041447231687381771809192998812504040261841248583680
print(type(large_int))
# <class 'int'>
print(large_int > sys.float_info.max)
# True
print(float('inf') > large_int)
# True
print(float(10**308))
# 1e+308
# print(float(10**309))
# OverflowError: int too large to convert to float