FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
circuitpython/tests/float/float1.py at master · ProGamerCode/circuitpython · GitHub
ProGamerCode
/
circuitpython
Public
forked from
adafruit/circuitpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
circuitpython
/
tests
/
float
/
float1.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
119 lines (100 loc) · 2.08 KB
Breadcrumbs
circuitpython
/
tests
/
float
/
float1.py
Copy path
File metadata and controls
119 lines (100 loc) · 2.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
110
111
112
113
114
115
116
117
118
119
# test basic float capabilities
# literals
print
(
.12
)
print
(
1.
)
print
(
1.2
)
print
(
0e0
)
print
(
0e+0
)
print
(
0e-0
)
# float construction
print
(
float
(
1.2
))
print
(
float
(
"1.2"
))
print
(
float
(
"+1"
))
print
(
float
(
"1e1"
))
print
(
float
(
"1e+1"
))
print
(
float
(
"1e-1"
))
print
(
float
(
"inf"
))
print
(
float
(
"-inf"
))
print
(
float
(
"INF"
))
print
(
float
(
"infinity"
))
print
(
float
(
"INFINITY"
))
print
(
float
(
"nan"
))
print
(
float
(
"-nan"
))
print
(
float
(
"NaN"
))
try
:
float
(
""
)
except
ValueError
:
print
(
"ValueError"
)
try
:
float
(
"1e+"
)
except
ValueError
:
print
(
"ValueError"
)
try
:
float
(
"1z"
)
except
ValueError
:
print
(
"ValueError"
)
# construct from something with the buffer protocol
print
(
float
(
b"1.2"
))
print
(
float
(
bytearray
(
b"3.4"
)))
# unary operators
print
(
bool
(
0.0
))
print
(
bool
(
1.2
))
print
(
+
(
1.2
))
print
(
-
(
1.2
))
# division of integers
x
=
1
/
2
print
(
x
)
# /= operator
a
=
1
a
/=
2
print
(
a
)
# floor division
print
(
1.0
//
2
)
print
(
2.0
//
2
)
# comparison
print
(
1.2
<=
3.4
)
print
(
1.2
<=
-
3.4
)
print
(
1.2
>=
3.4
)
print
(
1.2
>=
-
3.4
)
# comparison of nan is special
nan
=
float
(
'nan'
)
print
(
nan
==
1.2
)
print
(
nan
==
nan
)
try
:
1.0
/
0
except
ZeroDivisionError
:
print
(
"ZeroDivisionError"
)
try
:
1.0
//
0
except
ZeroDivisionError
:
print
(
"ZeroDivisionError"
)
try
:
1.2
%
0
except
ZeroDivisionError
:
print
(
"ZeroDivisionError"
)
try
:
0.0
**
-
1
except
ZeroDivisionError
:
print
(
"ZeroDivisionError"
)
# unsupported unary ops
try
:
~
1.2
except
TypeError
:
print
(
"TypeError"
)
try
:
1.2
in
3.4
except
TypeError
:
print
(
"TypeError"
)
# small int on LHS, float on RHS, unsupported op
try
:
print
(
1
|
1.0
)
except
TypeError
:
print
(
'TypeError'
)
# can't convert list to float
try
:
float
([])
except
TypeError
:
print
(
"TypeError"
)
# test constant float with more than 255 chars
x
=
1.84728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189
print
(
"%.5f"
%
x
)
Back
|
FazBrowse Home
|
New Git URL