OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * Representation of Dart integers containing integer specific | 8 * Representation of Dart integers containing integer specific |
9 * operations and specialization of operations inherited from [num]. | 9 * operations and specialization of operations inherited from [num]. |
10 * | 10 * |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 */ | 92 */ |
93 int operator >>(int shiftAmount); | 93 int operator >>(int shiftAmount); |
94 | 94 |
95 /** Returns true if and only if this integer is even. */ | 95 /** Returns true if and only if this integer is even. */ |
96 bool get isEven; | 96 bool get isEven; |
97 | 97 |
98 /** Returns true if and only if this integer is odd. */ | 98 /** Returns true if and only if this integer is odd. */ |
99 bool get isOdd; | 99 bool get isOdd; |
100 | 100 |
101 /** | 101 /** |
102 * Returns the minimum number of bits required to store this integer. | |
103 * | |
104 * The number of bits excludes the sign bit, which gives the natural length | |
105 * for non-negative (unsigned) values. Negative values are complemented to | |
106 * return the bit position of the first bit that differs from the sign bit. | |
107 * | |
108 * To find the the number of bits needed to store the value as a signed value, | |
109 * add one, i.e. use `x.bitLength + 1`. | |
110 * | |
111 * x.bitLength == (-x-1).bitLength | |
112 * | |
113 * 3.bitLength == 2; // 00000011 | |
114 * 2.bitLength == 2; // 00000010 | |
115 * 1.bitLength == 1; // 00000001 | |
116 * 0.bitLength == 0; // 00000000 | |
117 * (-1).bitLength == 0; // 11111111 | |
118 * (-2).bitLength == 1; // 11111110 | |
119 * (-3).bitLength == 2; // 11111101 | |
120 * (-4).bitLength == 2; // 11111100 | |
121 */ | |
122 int get bitLength; | |
123 | |
124 /** | |
125 * Returns the least significant [width] bits of this integer as a | |
126 * non-negative number (i.e. unsigned representation). The returned value has | |
127 * zeros in all bit positions higher than [width]. | |
128 * | |
129 * (-1).toUnsigned(5) == 32 // 11111111 -> 00011111 | |
130 * | |
131 * This operation can be used to simulate arithmetic from low level languages. | |
132 * For example, to increment an 8 bit quantity: | |
133 * | |
134 * q = (q + 1).toUnsigned(8); | |
135 */ | |
136 int toUnsigned(int width); | |
137 | |
138 /** | |
139 * Returns the least significant [width] bits of this integer, extending the | |
140 * highest retained bit to the sign. This is the same as truncating the value | |
141 * to fit in [width] bits using an signed 2-s complement representation. The | |
142 * returned value has the same bit value in all positions higher than [width]. | |
143 * | |
144 * V--sign bit-V | |
145 * 16.toSigned(5) == -16 // 00010000 -> 11110000 | |
146 * 239.toSigned(5) == 15 // 11101111 -> 00001111 | |
147 * ^ ^ | |
Lasse Reichstein Nielsen
2013/09/06 12:40:11
If I'm correct then
x == x.toSigned(x.bitLength
sra1
2013/09/06 22:11:57
I added this relation to the documentation.
| |
148 */ | |
149 int toSigned(int width); | |
150 | |
151 /** | |
102 * Return the negative value of this integer. | 152 * Return the negative value of this integer. |
103 * | 153 * |
104 * The result of negating an integer always has the opposite sign, except | 154 * The result of negating an integer always has the opposite sign, except |
105 * for zero, which is its own negation. | 155 * for zero, which is its own negation. |
106 */ | 156 */ |
107 int operator -(); | 157 int operator -(); |
108 | 158 |
109 /** | 159 /** |
110 * Returns the absolute value of this integer. | 160 * Returns the absolute value of this integer. |
111 * | 161 * |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 * value is used instead. If no [onError] is provided, a [FormatException] | 227 * value is used instead. If no [onError] is provided, a [FormatException] |
178 * is thrown. | 228 * is thrown. |
179 * | 229 * |
180 * The [onError] function is only invoked if [source] is a [String]. It is | 230 * The [onError] function is only invoked if [source] is a [String]. It is |
181 * not invoked if the [source] is, for example, `null`. | 231 * not invoked if the [source] is, for example, `null`. |
182 */ | 232 */ |
183 external static int parse(String source, | 233 external static int parse(String source, |
184 { int radix, | 234 { int radix, |
185 int onError(String source) }); | 235 int onError(String source) }); |
186 } | 236 } |
OLD | NEW |