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. */ |
|
justinfagnani
2013/08/14 17:06:51
Q for Kathy I guess: Should we doc the operators i
Chris Bracken
2013/08/14 17:45:31
Java doesn't provide operator overloads, but where
Kathy Walrath
2013/08/14 17:55:28
I'm against documenting the obvious. (The exceptio
Chris Bracken
2013/08/14 18:13:58
I think the real solution is for me to extend thes
| |
| 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); |
|
Kathy Walrath
2013/08/14 17:15:07
Nothing interesting to say here?
Chris Bracken
2013/08/14 17:45:31
compareTo() docs are picked up off Comparable. I c
Kathy Walrath
2013/08/14 17:55:28
Only if it's useful.
On 2013/08/14 17:45:31, Chri
| |
| 84 | |
| 37 bool operator ==(other); | 85 bool operator ==(other); |
|
Kathy Walrath
2013/08/14 17:15:07
Can we say anything here? Do we really want the su
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 86 | |
| 87 /** Relational less than operator. */ | |
| 38 bool operator <(other); | 88 bool operator <(other); |
| 89 | |
| 90 /** Relational less than or equal to operator. */ | |
| 39 bool operator <=(other); | 91 bool operator <=(other); |
| 92 | |
| 93 /** Relational greater than operator. */ | |
| 40 bool operator >(other); | 94 bool operator >(other); |
| 95 | |
| 96 /** Relational greater than or equal to operator. */ | |
| 41 bool operator >=(other); | 97 bool operator >=(other); |
| 42 | 98 |
| 43 // Testers. | 99 /** Returns `true` if and only if this integer is even. */ |
| 44 bool get isEven; | 100 bool get isEven; |
| 101 | |
| 102 /** | |
| 103 * Returns `true` if and only if this integer is the maximum signed value | |
| 104 * that can be represented within its bit size. | |
| 105 */ | |
| 45 bool get isMaxValue; | 106 bool get isMaxValue; |
| 107 | |
| 108 /** | |
| 109 * Returns `true` if and only if this integer is the minimum signed value | |
| 110 * that can be represented within its bit size. | |
| 111 */ | |
| 46 bool get isMinValue; | 112 bool get isMinValue; |
| 113 | |
| 114 /** Returns `true` if and only if this integer less than zero. */ | |
|
Kathy Walrath
2013/08/14 17:15:07
less -> is less
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 47 bool get isNegative; | 115 bool get isNegative; |
| 116 | |
| 117 /** Returns `true` if and only if this integer is odd. */ | |
| 48 bool get isOdd; | 118 bool get isOdd; |
| 119 | |
| 120 /** Returns `true` if and only if this integer is zero. */ | |
| 49 bool get isZero; | 121 bool get isZero; |
| 50 | 122 |
| 51 int get hashCode; | 123 int get hashCode; |
| 52 | 124 |
| 125 /** Returns the absolute value of this integer. */ | |
| 53 IntX abs(); | 126 IntX abs(); |
| 54 | 127 |
| 55 /** | 128 /** |
| 56 * Returns the number of leading zeros in this [IntX] as an [int] | 129 * Returns the number of high-order zeros in this integer's bit |
| 57 * between 0 and 64. | 130 * representation. |
| 58 */ | 131 */ |
| 59 int numberOfLeadingZeros(); | 132 int numberOfLeadingZeros(); |
| 60 | 133 |
| 61 /** | 134 /** |
| 62 * Returns the number of trailing zeros in this [IntX] as an [int] | 135 * Returns the number of low-order zeros in this integer's bit representation. |
| 63 * between 0 and 64. | |
| 64 */ | 136 */ |
| 65 int numberOfTrailingZeros(); | 137 int numberOfTrailingZeros(); |
| 66 | 138 |
| 67 /** | 139 /** |
| 68 * Converts this [IntX] to a [List] of [int], starting with the least | 140 * Returns a byte-sequence representation of this integer. |
| 141 * | |
| 142 * Returns a [List] of [int], one per byte, starting with the least | |
|
Kathy Walrath
2013/08/14 17:15:07
There's no need to link to the types, since you ge
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 69 * significant byte. | 143 * significant byte. |
| 70 */ | 144 */ |
| 71 List<int> toBytes(); | 145 List<int> toBytes(); |
| 72 | 146 |
| 73 /** | 147 /** |
| 74 * Converts this [IntX] to an [int]. On some platforms, inputs with large | 148 * Returns the [int] representation of this integer. |
|
Kathy Walrath
2013/08/14 17:15:07
[int] -> int
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 75 * absolute values (i.e., > 2^52) may lose some of their low bits. | 149 * |
| 150 * On some platforms, inputs with large absolute values (i.e., > 2^52) may | |
| 151 * lose some of their low-order bits. | |
| 76 */ | 152 */ |
| 77 int toInt(); | 153 int toInt(); |
| 78 | 154 |
| 79 /** | 155 /** |
| 80 * Converts an [IntX] to 32 bits. Narrower values are sign extended and | 156 * Returns an [Int32] representation of this integer. |
|
Kathy Walrath
2013/08/14 17:15:07
[Int32] -> Int32
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 81 * wider values have their high bits truncated. | 157 * |
| 158 * Narrower values are sign-extended and wider values have their high bits | |
| 159 * truncated. | |
| 82 */ | 160 */ |
| 83 Int32 toInt32(); | 161 Int32 toInt32(); |
| 84 | 162 |
| 85 /** | 163 /** Returns an [Int64] representation of this integer. */ |
|
Kathy Walrath
2013/08/14 17:15:07
[Int64] -> Int64
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 86 * Converts an [IntX] to 64 bits. | |
| 87 */ | |
| 88 Int64 toInt64(); | 164 Int64 toInt64(); |
| 89 | 165 |
| 90 /** | 166 /** Returns a decimal [String] representation of this integer. */ |
|
Kathy Walrath
2013/08/14 17:15:07
I had a hard time reading this at first. How about
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 91 * Returns the value of this [IntX] as a decimal [String]. | |
| 92 */ | |
| 93 String toString(); | 167 String toString(); |
| 94 | 168 |
| 95 /** | 169 /** Returns a hexadecimal [String] representation of this integer. */ |
|
Kathy Walrath
2013/08/14 17:15:07
Maybe:
Returns a string representing the hexadeci
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 96 * Returns the value of this [IntX] as a hexadecimal [String]. | |
| 97 */ | |
| 98 String toHexString(); | 170 String toHexString(); |
| 99 | 171 |
| 100 /** | 172 /** |
| 101 * Returns the value of this [IntX] as a [String] in the given radix. | 173 * Returns a [String] representation of this integer in the given radix. |
|
Kathy Walrath
2013/08/14 17:15:07
Maybe:
Returns a string representing the value of
Chris Bracken
2013/08/14 17:45:31
Done.
| |
| 102 * [radix] must be an integer between 2 and 16, inclusive. | 174 * |
| 175 * [radix] must be an integer in the range 2 .. 16, inclusive. | |
| 103 */ | 176 */ |
| 104 String toRadixString(int radix); | 177 String toRadixString(int radix); |
| 105 } | 178 } |
| OLD | NEW |