Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1944)

Side by Side Diff: pkg/fixnum/lib/src/intx.dart

Issue 1909043004: Moved pkg/fixnum to github (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/fixnum/lib/src/int64.dart ('k') | pkg/fixnum/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of fixnum;
6
7 /**
8 * A fixed-precision integer.
9 */
10 abstract class IntX implements Comparable<IntX> {
11
12 /** Addition operator. */
13 IntX operator +(other);
14
15 /** Subtraction operator. */
16 IntX operator -(other);
17
18 /**
19 * Negate operator.
20 *
21 * Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow.
22 */
23 IntX operator -();
24
25 /** Multiplication operator. */
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 */
35 IntX operator %(other);
36
37 /** Truncating division operator. */
38 IntX operator ~/(other);
39
40 /**
41 * Returns the remainder of the truncating division of this integer by
42 * [other].
43 */
44 IntX remainder(other);
45
46 /** Bitwise and operator. */
47 IntX operator &(other);
48
49 /** Bitwise or operator. */
50 IntX operator |(other);
51
52 /** Bitwise xor operator. */
53 IntX operator ^(other);
54
55 /** Bitwise negate 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 */
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 */
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 */
81 IntX shiftRightUnsigned(int shiftAmount);
82
83 /**
84 * Returns `true` if and only if [other] is an int or IntX equal in
85 * value to this integer.
86 */
87 bool operator ==(other);
88
89 /** Relational less than operator. */
90 bool operator <(other);
91
92 /** Relational less than or equal to operator. */
93 bool operator <=(other);
94
95 /** Relational greater than operator. */
96 bool operator >(other);
97
98 /** Relational greater than or equal to operator. */
99 bool operator >=(other);
100
101 /** Returns `true` if and only if this integer is even. */
102 bool get isEven;
103
104 /**
105 * Returns `true` if and only if this integer is the maximum signed value
106 * that can be represented within its bit size.
107 */
108 bool get isMaxValue;
109
110 /**
111 * Returns `true` if and only if this integer is the minimum signed value
112 * that can be represented within its bit size.
113 */
114 bool get isMinValue;
115
116 /** Returns `true` if and only if this integer is less than zero. */
117 bool get isNegative;
118
119 /** Returns `true` if and only if this integer is odd. */
120 bool get isOdd;
121
122 /** Returns `true` if and only if this integer is zero. */
123 bool get isZero;
124
125 int get hashCode;
126
127 /** Returns the absolute value of this integer. */
128 IntX abs();
129
130 /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */
131 IntX clamp(lowerLimit, upperLimit);
132
133 /**
134 * Returns the minimum number of bits required to store this integer.
135 *
136 * The number of bits excludes the sign bit, which gives the natural length
137 * for non-negative (unsigned) values. Negative values are complemented to
138 * return the bit position of the first bit that differs from the sign bit.
139 *
140 * To find the the number of bits needed to store the value as a signed value,
141 * add one, i.e. use `x.bitLength + 1`.
142 */
143 int get bitLength;
144
145 /**
146 * Returns the number of high-order zeros in this integer's bit
147 * representation.
148 */
149 int numberOfLeadingZeros();
150
151 /**
152 * Returns the number of low-order zeros in this integer's bit representation.
153 */
154 int numberOfTrailingZeros();
155
156 /**
157 * Returns the least significant [width] bits of this integer, extending the
158 * highest retained bit to the sign. This is the same as truncating the value
159 * to fit in [width] bits using an signed 2-s complement representation. The
160 * returned value has the same bit value in all positions higher than [width].
161 *
162 * If the input value fits in [width] bits without truncation, the result is
163 * the same as the input. The minimum width needed to avoid truncation of `x`
164 * is `x.bitLength + 1`, i.e.
165 *
166 * x == x.toSigned(x.bitLength + 1);
167 */
168 IntX toSigned(int width);
169
170 /**
171 * Returns the least significant [width] bits of this integer as a
172 * non-negative number (i.e. unsigned representation). The returned value has
173 * zeros in all bit positions higher than [width].
174 *
175 * If the input fits in [width] bits without truncation, the result is the
176 * same as the input. The minimum width needed to avoid truncation of `x` is
177 * given by `x.bitLength`, i.e.
178 *
179 * x == x.toUnsigned(x.bitLength);
180 */
181 IntX toUnsigned(int width);
182
183 /**
184 * Returns a byte-sequence representation of this integer.
185 *
186 * Returns a list of int, starting with the least significant byte.
187 */
188 List<int> toBytes();
189
190 /**
191 * Returns the double representation of this integer.
192 *
193 * On some platforms, inputs with large absolute values (i.e., > 2^52) may
194 * lose some of their low-order bits.
195 */
196 double toDouble();
197
198 /**
199 * Returns the int representation of this integer.
200 *
201 * On some platforms, inputs with large absolute values (i.e., > 2^52) may
202 * lose some of their low-order bits.
203 */
204 int toInt();
205
206 /**
207 * Returns an Int32 representation of this integer.
208 *
209 * Narrower values are sign-extended and wider values have their high bits
210 * truncated.
211 */
212 Int32 toInt32();
213
214 /** Returns an Int64 representation of this integer. */
215 Int64 toInt64();
216
217 /**
218 * Returns a string representing the value of this integer in decimal
219 * notation; example: `'13'`.
220 */
221 String toString();
222
223 /**
224 * Returns a string representing the value of this integer in hexadecimal
225 * notation; example: `'0xd'`.
226 */
227 String toHexString();
228
229 /**
230 * Returns a string representing the value of this integer in the given radix.
231 *
232 * [radix] must be an integer in the range 2 .. 16, inclusive.
233 */
234 String toRadixString(int radix);
235 }
OLDNEW
« no previous file with comments | « pkg/fixnum/lib/src/int64.dart ('k') | pkg/fixnum/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698