Mercurial > octave
comparison test/integer.tst @ 28589:d5f9c8911090
* integer.tst: New tests for integer constants.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 21 Jul 2020 14:23:03 -0400 |
parents | bd51beb6205e |
children | 5b1143d1d74b |
comparison
equal
deleted
inserted
replaced
28588:ee9b1081471f | 28589:d5f9c8911090 |
---|---|
48 %! xmult = clsmax * 2; | 48 %! xmult = clsmax * 2; |
49 %! assert (xmult, clsmax); | 49 %! assert (xmult, clsmax); |
50 %! xdiv = clsmax / 0.5; | 50 %! xdiv = clsmax / 0.5; |
51 %! assert (xdiv, clsmax); | 51 %! assert (xdiv, clsmax); |
52 %! endfor | 52 %! endfor |
53 | |
54 ## Tests for binary constants | |
55 %!assert (0b1, uint8 (2^0)) | |
56 %!assert (0b10000000, uint8 (2^7)) | |
57 %!assert (0b11111111, intmax ("uint8")) | |
58 %!assert (0b100000000, uint16 (2^8)) | |
59 %!assert (0b1000000000000000, uint16 (2^15)) | |
60 %!assert (0b1111111111111111, intmax ("uint16")) | |
61 %!assert (0b10000000000000000, uint32 (2^16)) | |
62 %!assert (0b10000000000000000000000000000000, uint32 (2^31)) | |
63 %!assert (0b11111111111111111111111111111111, intmax ("uint32")) | |
64 %!assert (0b100000000000000000000000000000000, uint64 (2^32)) | |
65 %!assert (0b1000000000000000000000000000000000000000000000000000000000000000, uint64 (2^63)) | |
66 %!assert (0b1111111111111111111111111111111111111111111111111111111111111111, intmax ("uint64")) | |
67 %!error <too many digits for binary constant> eval ("0b11111111111111111111111111111111111111111111111111111111111111111") | |
68 | |
69 %!assert (0b1u16, uint16 (2^0)) | |
70 %!assert (0b10000000u16, uint16 (2^7)) | |
71 | |
72 %!assert (0b1u32, uint32 (2^0)) | |
73 %!assert (0b10000000u32, uint32 (2^7)) | |
74 %!assert (0b1000000000000000u32, uint32 (2^15)) | |
75 | |
76 %!assert (0b1u64, uint64 (2^0)) | |
77 %!assert (0b10000000u64, uint64 (2^7)) | |
78 %!assert (0b1000000000000000u64, uint64 (2^15)) | |
79 %!assert (0b10000000000000000000000000000000u64, uint64 (2^31)) | |
80 | |
81 %!assert (0b1s16, int16 (2^0)) | |
82 %!assert (0b10000000s16, int16 (2^7)) | |
83 | |
84 %!assert (0b1s32, int32 (2^0)) | |
85 %!assert (0b10000000s32, int32 (2^7)) | |
86 %!assert (0b1000000000000000s32, int32 (2^15)) | |
87 | |
88 %!assert (0b1s64, int64 (2^0)) | |
89 %!assert (0b10000000s64, int64 (2^7)) | |
90 %!assert (0b1000000000000000s64, int64 (2^15)) | |
91 %!assert (0b10000000000000000000000000000000s64, int64 (2^31)) | |
92 | |
93 ## Tests for hexadecimal constants | |
94 %!assert (0x1, uint8 (2^0)) | |
95 %!assert (0x80, uint8 (2^7)) | |
96 %!assert (0xff, intmax ("uint8")) | |
97 %!assert (0x100, uint16 (2^8)) | |
98 %!assert (0x8000, uint16 (2^15)) | |
99 %!assert (0xffff, intmax ("uint16")) | |
100 %!assert (0x10000, uint32 (2^16)) | |
101 %!assert (0x80000000, uint32 (2^31)) | |
102 %!assert (0xffffffff, intmax ("uint32")) | |
103 %!assert (0x100000000, uint64 (2^32)) | |
104 %!assert (0x8000000000000000, uint64 (2^63)) | |
105 %!assert (0xffffffffffffffff, intmax ("uint64")) | |
106 %!error <too many digits for hexadecimal constant> eval ("0xfffffffffffffffff") | |
107 | |
108 %!assert (0x1u16, uint16 (2^0)) | |
109 %!assert (0x80u16, uint16 (2^7)) | |
110 | |
111 %!assert (0x1u32, uint32 (2^0)) | |
112 %!assert (0x80u32, uint32 (2^7)) | |
113 %!assert (0x8000u32, uint32 (2^15)) | |
114 | |
115 %!assert (0x1u64, uint64 (2^0)) | |
116 %!assert (0x80u64, uint64 (2^7)) | |
117 %!assert (0x8000u64, uint64 (2^15)) | |
118 %!assert (0x80000000u64, uint64 (2^31)) | |
119 | |
120 %!assert (0x1s16, int16 (2^0)) | |
121 %!assert (0x80s16, int16 (2^7)) | |
122 | |
123 %!assert (0x1s32, int32 (2^0)) | |
124 %!assert (0x80s32, int32 (2^7)) | |
125 %!assert (0x8000s32, int32 (2^15)) | |
126 | |
127 %!assert (0x1s64, int64 (2^0)) | |
128 %!assert (0x80s64, int64 (2^7)) | |
129 %!assert (0x8000s64, int64 (2^15)) | |
130 %!assert (0x80000000s64, int64 (2^31)) | |
131 | |
132 ## Tests for decimal constants with extreme values | |
133 | |
134 %!assert (uint64 (9007199254740992), uint64 (flintmax ())) | |
135 %!assert (int64 (9007199254740992), int64 (flintmax ())) | |
136 %!assert (uint64 (-9007199254740992), uint64 (-flintmax ())) | |
137 %!assert (int64 (-9007199254740992), int64 (-flintmax ())) | |
138 | |
139 %!assert (uint64 (9007199254740993), uint64 (flintmax ())+1) | |
140 %!assert (int64 (9007199254740993), int64 (flintmax ())+1) | |
141 %!assert (uint64 (-9007199254740993), uint64 (-flintmax ())-1) | |
142 %!assert (int64 (-9007199254740993), int64 (-flintmax ())-1) | |
143 | |
144 %!assert (uint64 (18446744073709551615), intmax ("uint64")) | |
145 | |
146 %!assert (int64 (9223372036854775807), intmax ("int64")) | |
147 %!assert (int64 (-9223372036854775808), intmin ("int64")) |