cython

Форк
0
/
cpp_stl_bit_cpp20.pyx 
131 строка · 2.8 Кб
1
# mode: run
2
# tag: cpp, werror, cpp20
3

4
from libcpp cimport bool
5
from libc.stdint cimport uint8_t, int8_t
6
from libcpp.bit cimport (bit_cast, has_single_bit, bit_ceil, bit_floor, 
7
                        bit_width, rotr, rotl, countl_zero, countl_one, countr_zero, 
8
                        countr_one, popcount)
9

10
def test_bit_cast():
11
    """
12
    Test bit_cast with a signed 8bit wide integer type.
13
    -127U = 0b1000'0001U
14
    >>> test_bit_cast()
15
    129
16
    """
17
    cdef int8_t x = -127
18
    cdef result = bit_cast[uint8_t, int8_t](x)
19
    return result
20

21
def test_has_single_bit():
22
    """
23
    Test has_single_bit with a unsigned 8bit wide integer type.
24
    >>> test_has_single_bit()
25
    True
26
    """
27
    cdef uint8_t x = 1
28
    cdef bint res = has_single_bit[uint8_t](x)
29
    return res
30

31
def test_bit_ceil():
32
    """
33
    Test bit_ceil with a unsigned 8bit wide integer type.
34
    >>> test_bit_ceil()
35
    4
36
    """
37
    cdef uint8_t x = 3
38
    cdef uint8_t res = bit_ceil[uint8_t](x)
39
    return res
40

41
def test_bit_floor():
42
    """
43
    Test bit_floor with a unsigned 8bit wide integer type.
44
    >>> test_bit_floor()
45
    4
46
    """
47
    cdef uint8_t x = 5
48
    cdef uint8_t res = bit_floor[uint8_t](x)
49
    return res
50

51
def test_bit_width():
52
    """
53
    Test bit_width with a unsigned 8bit wide integer type.
54
    >>> test_bit_width()
55
    3
56
    """
57
    cdef uint8_t x = 5
58
    cdef int res = bit_width[uint8_t](x)
59
    return res
60

61
def test_rotl():
62
    """
63
    Test rotl with a unsigned 8bit wide integer type.
64
    >>> test_rotl()
65
    209
66
    """
67
    cdef uint8_t x = 29
68
    cdef int s = 4
69
    cdef uint8_t res = rotl[uint8_t](x, s)
70
    return res
71

72
def test_rotr():
73
    """
74
    Test rotr with a unsigned 8bit wide integer type.
75
    >>> test_rotr()
76
    142
77
    """
78
    cdef uint8_t x = 29
79
    cdef int s = 1
80
    cdef uint8_t res = rotr[uint8_t](x, s)
81
    return res
82

83
def test_countl_zero():
84
    """
85
    Test countl_zero with a unsigned 8bit wide integer type.
86
    >>> test_countl_zero()
87
    3
88
    """
89
    cdef uint8_t x = 24
90
    cdef int res = countl_zero[uint8_t](x)
91
    return res
92

93
def test_countr_zero():
94
    """
95
    Test countr_zero with a unsigned 8bit wide integer type.
96
    >>> test_countr_zero()
97
    3
98
    """
99
    cdef uint8_t x = 24
100
    cdef int res = countr_zero[uint8_t](x)
101
    return res
102

103
def test_countl_one():
104
    """
105
    Test countl_one with a unsigned 8bit wide integer type.
106
    >>> test_countl_one()
107
    3
108
    """
109
    cdef uint8_t x = 231
110
    cdef int res = countl_one[uint8_t](x)
111
    return res
112

113
def test_countr_one():
114
    """
115
    Test countr_one with a unsigned 8bit wide integer type.
116
    >>> test_countr_one()
117
    3
118
    """
119
    cdef uint8_t x = 231
120
    cdef int res = countr_one[uint8_t](x)
121
    return res
122

123
def test_popcount():
124
    """
125
    Test popcount with a unsigned 8bit wide integer type.
126
    >>> test_popcount()
127
    8
128
    """
129
    cdef uint8_t x = 255
130
    cdef int res = popcount[uint8_t](x)
131
    return res
132

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.