Chromium Code Reviews| 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 { |
| 11 | 11 |
| 12 // Arithmetic operations. | 12 /** Addition operator. */ |
| 13 IntX operator +(other); | 13 IntX operator +(other); |
| 14 | |
| 15 /** Subtraction operator. */ | |
| 14 IntX operator -(other); | 16 IntX operator -(other); |
| 15 // The unary '-' operator. Note that -MIN_VALUE will be equal | 17 |
| 16 // to MIN_VALUE due to overflow. | 18 /** |
| 19 * Negate operator. | |
| 20 * | |
| 21 * Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow. | |
| 22 */ | |
| 17 IntX operator -(); | 23 IntX operator -(); |
| 24 | |
| 25 /** Multiplication operator. */ | |
| 18 IntX operator *(other); | 26 IntX operator *(other); |
| 27 | |
| 28 /** | |
| 29 * Euclidean modulo operator. | |
| 30 * | |
| 31 * Returns the remainder of the euclidean division. The euclidean division | |
| 32 * of two integers `a` and `b` yields two integers `q` and `r` such that | |
| 33 * `a == b * q + r` and `0 <= r < a.abs()`. | |
| 34 */ | |
| 19 IntX operator %(other); | 35 IntX operator %(other); |
| 20 // Truncating division. | 36 |
| 37 /** Truncating division operator. */ | |
| 21 IntX operator ~/(other); | 38 IntX operator ~/(other); |
| 39 | |
| 40 /** | |
| 41 * Returns the remainder of the truncating division of this integer by | |
| 42 * [other]. | |
| 43 */ | |
| 22 IntX remainder(other); | 44 IntX remainder(other); |
| 23 | 45 |
| 24 // Note: no / operator | 46 /** Bitwise and operator. */ |
| 47 IntX operator &(other); | |
| 25 | 48 |
| 26 // Bit-operations. | 49 /** Bitwise or operator. */ |
| 27 IntX operator &(other); | |
| 28 IntX operator |(other); | 50 IntX operator |(other); |
| 51 | |
| 52 /** Bitwise xor operator. */ | |
| 29 IntX operator ^(other); | 53 IntX operator ^(other); |
| 54 | |
| 55 /** Bitwise negate operator. */ | |
| 30 IntX operator ~(); | 56 IntX operator ~(); |
| 57 | |
| 58 /** | |
| 59 * Left bit-shift operator. | |
| 60 * | |
| 61 * Returns the result of shifting the bits of this integer by [shiftAmount] | |
| 62 * bits to the left. Low-order bits are filled with zeros. | |
| 63 */ | |
| 31 IntX operator <<(int shiftAmount); | 64 IntX operator <<(int shiftAmount); |
| 65 | |
| 66 /** | |
| 67 * Right bit-shift operator. | |
| 68 * | |
| 69 * Returns the result of shifting the bits of this integer by [shiftAmount] | |
| 70 * bits to the right. High-order bits are filled with zero in the case where | |
| 71 * this integer is positive, or one in the case where it is negative. | |
| 72 */ | |
| 32 IntX operator >>(int shiftAmount); | 73 IntX operator >>(int shiftAmount); |
| 74 | |
| 75 /** | |
| 76 * Unsigned right-shift operator. | |
| 77 * | |
| 78 * Returns the result of shifting the bits of this integer by [shiftAmount] | |
| 79 * bits to the right. High-order bits are filled with zeros. | |
| 80 */ | |
| 33 IntX shiftRightUnsigned(int shiftAmount); | 81 IntX shiftRightUnsigned(int shiftAmount); |
| 34 | 82 |
| 35 // Relational operations, may be applied to IntX or int. | |
| 36 int compareTo(Comparable other); | 83 int compareTo(Comparable other); |
| 84 | |
| 85 /** | |
| 86 * Returns `true` if and only if [other] is an int or IntX equal in | |
| 87 * value to this integer. | |
| 88 */ | |
| 37 bool operator ==(other); | 89 bool operator ==(other); |
| 90 | |
| 91 /** Relational less than operator. */ | |
| 38 bool operator <(other); | 92 bool operator <(other); |
| 93 | |
| 94 /** Relational less than or equal to operator. */ | |
| 39 bool operator <=(other); | 95 bool operator <=(other); |
| 96 | |
| 97 /** Relational greater than operator. */ | |
| 40 bool operator >(other); | 98 bool operator >(other); |
| 99 | |
| 100 /** Relational greater than or equal to operator. */ | |
| 41 bool operator >=(other); | 101 bool operator >=(other); |
| 42 | 102 |
| 43 // Testers. | 103 /** Returns `true` if and only if this integer is even. */ |
| 44 bool get isEven; | 104 bool get isEven; |
| 105 | |
| 106 /** | |
| 107 * Returns `true` if and only if this integer is the maximum signed value | |
| 108 * that can be represented within its bit size. | |
| 109 */ | |
| 45 bool get isMaxValue; | 110 bool get isMaxValue; |
| 111 | |
| 112 /** | |
| 113 * Returns `true` if and only if this integer is the minimum signed value | |
| 114 * that can be represented within its bit size. | |
| 115 */ | |
| 46 bool get isMinValue; | 116 bool get isMinValue; |
| 117 | |
| 118 /** Returns `true` if and only if this integer is less than zero. */ | |
| 47 bool get isNegative; | 119 bool get isNegative; |
| 120 | |
| 121 /** Returns `true` if and only if this integer is odd. */ | |
| 48 bool get isOdd; | 122 bool get isOdd; |
| 123 | |
| 124 /** Returns `true` if and only if this integer is zero. */ | |
| 49 bool get isZero; | 125 bool get isZero; |
| 50 | 126 |
| 51 int get hashCode; | 127 int get hashCode; |
| 52 | 128 |
| 129 /** Returns the absolute value of this integer. */ | |
| 53 IntX abs(); | 130 IntX abs(); |
| 54 | 131 |
| 55 /** | 132 /** |
| 56 * Returns the number of leading zeros in this [IntX] as an [int] | 133 * Returns the number of high-order zeros in this integer's bit |
| 57 * between 0 and 64. | 134 * representation. |
| 58 */ | 135 */ |
| 59 int numberOfLeadingZeros(); | 136 int numberOfLeadingZeros(); |
| 60 | 137 |
| 61 /** | 138 /** |
| 62 * Returns the number of trailing zeros in this [IntX] as an [int] | 139 * Returns the number of low-order zeros in this integer's bit representation. |
| 63 * between 0 and 64. | |
| 64 */ | 140 */ |
| 65 int numberOfTrailingZeros(); | 141 int numberOfTrailingZeros(); |
| 66 | 142 |
| 67 /** | 143 /** |
| 68 * Converts this [IntX] to a [List] of [int], starting with the least | 144 * Returns a byte-sequence representation of this integer. |
| 69 * significant byte. | 145 * |
| 146 * Returns a list of int, starting with the least significant byte. | |
| 70 */ | 147 */ |
| 71 List<int> toBytes(); | 148 List<int> toBytes(); |
| 72 | 149 |
| 73 /** | 150 /** |
| 74 * Converts this [IntX] to an [int]. On some platforms, inputs with large | 151 * Returns the int representation of this integer. |
| 75 * absolute values (i.e., > 2^52) may lose some of their low bits. | 152 * |
| 153 * On some platforms, inputs with large absolute values (i.e., > 2^52) may | |
| 154 * lose some of their low-order bits. | |
| 76 */ | 155 */ |
| 77 int toInt(); | 156 int toInt(); |
| 78 | 157 |
| 79 /** | 158 /** |
| 80 * Converts an [IntX] to 32 bits. Narrower values are sign extended and | 159 * Returns an Int32 representation of this integer. |
| 81 * wider values have their high bits truncated. | 160 * |
| 161 * Narrower values are sign-extended and wider values have their high bits | |
| 162 * truncated. | |
| 82 */ | 163 */ |
| 83 Int32 toInt32(); | 164 Int32 toInt32(); |
| 84 | 165 |
| 85 /** | 166 /** Returns an Int64 representation of this integer. */ |
| 86 * Converts an [IntX] to 64 bits. | |
| 87 */ | |
| 88 Int64 toInt64(); | 167 Int64 toInt64(); |
| 89 | 168 |
| 90 /** | 169 /** |
| 91 * Returns the value of this [IntX] as a decimal [String]. | 170 * Returns a string representating the value of this integer in decimal |
|
Kathy Walrath
2013/08/14 17:55:28
representating!!
->
representing
(though I like r
Chris Bracken
2013/08/14 18:13:58
Whoops - missed a couple backspaces. Done.
| |
| 171 * notation; example: `13`. | |
|
Kathy Walrath
2013/08/14 17:55:28
shouldn't this have quotation marks, since it's a
Chris Bracken
2013/08/14 18:13:58
Done.
| |
| 92 */ | 172 */ |
| 93 String toString(); | 173 String toString(); |
| 94 | 174 |
| 95 /** | 175 /** |
| 96 * Returns the value of this [IntX] as a hexadecimal [String]. | 176 * Returns a string representing the value of this integer in hexadecimal |
| 177 * notation; example: `0xd`. | |
|
Kathy Walrath
2013/08/14 17:55:28
quotation marks?
Chris Bracken
2013/08/14 18:13:58
Done.
| |
| 97 */ | 178 */ |
| 98 String toHexString(); | 179 String toHexString(); |
| 99 | 180 |
| 100 /** | 181 /** |
| 101 * Returns the value of this [IntX] as a [String] in the given radix. | 182 * Returns a string representing the value of this integer in the given radix. |
| 102 * [radix] must be an integer between 2 and 16, inclusive. | 183 * |
| 184 * [radix] must be an integer in the range 2 .. 16, inclusive. | |
| 103 */ | 185 */ |
| 104 String toRadixString(int radix); | 186 String toRadixString(int radix); |
| 105 } | 187 } |
| OLD | NEW |