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
| import ctypes as ct
|
|
| class FloatBits(ct.Structure):
| _fields_ = [
| ('M', ct.c_uint, 23),
| ('E', ct.c_uint, 8),
| ('S', ct.c_uint, 1)
| ]
|
|
| class Float(ct.Union):
| _anonymous_ = ('bits',)
| _fields_ = [
| ('value', ct.c_float),
| ('bits', FloatBits)
| ]
|
|
| def nextpow2(x):
| if x < 0:
| x = -x
| if x == 0:
| return 0
| d = Float()
| d.value = x
| if d.M == 0:
| return d.E - 127
| return d.E - 127 + 1
|
|