| 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 fixnum; | 5 part of fixnum; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A fixed-precision integer. | 8 * A fixed-precision integer. |
| 9 */ | 9 */ |
| 10 abstract class IntX implements Comparable { | 10 abstract class IntX implements Comparable { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 bool get isOdd; | 122 bool get isOdd; |
| 123 | 123 |
| 124 /** Returns `true` if and only if this integer is zero. */ | 124 /** Returns `true` if and only if this integer is zero. */ |
| 125 bool get isZero; | 125 bool get isZero; |
| 126 | 126 |
| 127 int get hashCode; | 127 int get hashCode; |
| 128 | 128 |
| 129 /** Returns the absolute value of this integer. */ | 129 /** Returns the absolute value of this integer. */ |
| 130 IntX abs(); | 130 IntX abs(); |
| 131 | 131 |
| 132 /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */ |
| 133 IntX clamp(IntX lowerLimit, IntX upperLimit); |
| 134 |
| 135 /** |
| 136 * Returns the minimum number of bits required to store this integer. |
| 137 * |
| 138 * The number of bits excludes the sign bit, which gives the natural length |
| 139 * for non-negative (unsigned) values. Negative values are complemented to |
| 140 * return the bit position of the first bit that differs from the sign bit. |
| 141 * |
| 142 * To find the the number of bits needed to store the value as a signed value, |
| 143 * add one, i.e. use `x.bitLength + 1`. |
| 144 */ |
| 145 int get bitLength; |
| 146 |
| 132 /** | 147 /** |
| 133 * Returns the number of high-order zeros in this integer's bit | 148 * Returns the number of high-order zeros in this integer's bit |
| 134 * representation. | 149 * representation. |
| 135 */ | 150 */ |
| 136 int numberOfLeadingZeros(); | 151 int numberOfLeadingZeros(); |
| 137 | 152 |
| 138 /** | 153 /** |
| 139 * Returns the number of low-order zeros in this integer's bit representation. | 154 * Returns the number of low-order zeros in this integer's bit representation. |
| 140 */ | 155 */ |
| 141 int numberOfTrailingZeros(); | 156 int numberOfTrailingZeros(); |
| 142 | 157 |
| 143 /** | 158 /** |
| 159 * Returns the least significant [width] bits of this integer, extending the |
| 160 * highest retained bit to the sign. This is the same as truncating the value |
| 161 * to fit in [width] bits using an signed 2-s complement representation. The |
| 162 * returned value has the same bit value in all positions higher than [width]. |
| 163 * |
| 164 * If the input value fits in [width] bits without truncation, the result is |
| 165 * the same as the input. The minimum width needed to avoid truncation of `x` |
| 166 * is `x.bitLength + 1`, i.e. |
| 167 * |
| 168 * x == x.toSigned(x.bitLength + 1); |
| 169 */ |
| 170 IntX toSigned(int width); |
| 171 |
| 172 /** |
| 173 * Returns the least significant [width] bits of this integer as a |
| 174 * non-negative number (i.e. unsigned representation). The returned value has |
| 175 * zeros in all bit positions higher than [width]. |
| 176 * |
| 177 * If the input fits in [width] bits without truncation, the result is the |
| 178 * same as the input. The minimum width needed to avoid truncation of `x` is |
| 179 * given by `x.bitLength`, i.e. |
| 180 * |
| 181 * x == x.toUnsigned(x.bitLength); |
| 182 */ |
| 183 IntX toUnsigned(int width); |
| 184 |
| 185 /** |
| 144 * Returns a byte-sequence representation of this integer. | 186 * Returns a byte-sequence representation of this integer. |
| 145 * | 187 * |
| 146 * Returns a list of int, starting with the least significant byte. | 188 * Returns a list of int, starting with the least significant byte. |
| 147 */ | 189 */ |
| 148 List<int> toBytes(); | 190 List<int> toBytes(); |
| 149 | 191 |
| 150 /** | 192 /** |
| 193 * Returns the double representation of this integer. |
| 194 * |
| 195 * On some platforms, inputs with large absolute values (i.e., > 2^52) may |
| 196 * lose some of their low-order bits. |
| 197 */ |
| 198 double toDouble(); |
| 199 |
| 200 /** |
| 151 * Returns the int representation of this integer. | 201 * Returns the int representation of this integer. |
| 152 * | 202 * |
| 153 * On some platforms, inputs with large absolute values (i.e., > 2^52) may | 203 * On some platforms, inputs with large absolute values (i.e., > 2^52) may |
| 154 * lose some of their low-order bits. | 204 * lose some of their low-order bits. |
| 155 */ | 205 */ |
| 156 int toInt(); | 206 int toInt(); |
| 157 | 207 |
| 158 /** | 208 /** |
| 159 * Returns an Int32 representation of this integer. | 209 * Returns an Int32 representation of this integer. |
| 160 * | 210 * |
| (...skipping 17 matching lines...) Expand all Loading... |
| 178 */ | 228 */ |
| 179 String toHexString(); | 229 String toHexString(); |
| 180 | 230 |
| 181 /** | 231 /** |
| 182 * Returns a string representing the value of this integer in the given radix. | 232 * Returns a string representing the value of this integer in the given radix. |
| 183 * | 233 * |
| 184 * [radix] must be an integer in the range 2 .. 16, inclusive. | 234 * [radix] must be an integer in the range 2 .. 16, inclusive. |
| 185 */ | 235 */ |
| 186 String toRadixString(int radix); | 236 String toRadixString(int radix); |
| 187 } | 237 } |
| OLD | NEW |