Moved pkg/fixnum to github

The other changes to DEPS are purely ordering

R=sra@google.com

Review URL: https://codereview.chromium.org/1909043004 .
This commit is contained in:
Kevin Moore 2016-04-21 11:07:51 -07:00
parent 4367fd8800
commit 9c5e6fa304
10 changed files with 19 additions and 2847 deletions

35
DEPS
View file

@ -31,6 +31,9 @@ vars = {
# Revisions of /third_party/* dependencies.
"args_tag": "@0.13.4",
"async_tag": "@1.9.0",
"barback-0.13.0_rev": "@34853",
"barback-0.14.0_rev": "@36398",
"barback-0.14.1_rev": "@38525",
"barback_tag" : "@0.15.2+7",
"bazel_worker_tag": "@v0.1.0",
"boolean_selector_tag" : "@1.0.0",
@ -43,16 +46,17 @@ vars = {
"crypto_tag" : "@1.1.0",
"csslib_tag" : "@0.12.0",
"dart2js_info_rev" : "@0a221eaf16aec3879c45719de656680ccb80d8a1",
"dartdoc_tag" : "@v0.9.0",
"dart_services_rev" : "@7aea2574e6f3924bf409a80afb8ad52aa2be4f97",
"dart_style_tag": "@0.2.4",
"dartdoc_tag" : "@v0.9.0",
"dev_compiler_rev": "@0ed6aeca35fa0e618ad0f7f19f3eba64afdd80c4",
"fixnum_tag": "@0.10.4",
"func_rev": "@8d4aea75c21be2179cb00dc2b94a71414653094e",
"glob_rev": "@704cf75e4f26b417505c5c611bdaacd8808467dd",
"html_tag" : "@0.12.1+1",
"http_tag" : "@0.11.3+3",
"http_multi_server_tag" : "@2.0.0",
"http_parser_tag" : "@1.1.0",
"http_tag" : "@0.11.3+3",
"http_throttle_rev" : "@a81f08be942cdd608883c7b67795c12226abc235",
"idl_parser_rev": "@7fbe68cab90c38147dee4f48c30ad0d496c17915",
"intl_rev": "@a8b480b9c436f6c0ec16730804c914bdb4e30d53",
@ -66,49 +70,46 @@ vars = {
"mime_rev": "@75890811d4af5af080351ba8a2853ad4c8df98dd",
"mustache4dart_rev" : "@5724cfd85151e5b6b53ddcd3380daf188fe47f92",
"oauth2_tag": "@1.0.0",
"observe_rev": "@eee2b8ec34236fa46982575fbccff84f61202ac6",
"observatory_pub_packages_rev": "@cf90eb9077177d3d6b3fd5e8289477c2385c026a",
"observe_rev": "@eee2b8ec34236fa46982575fbccff84f61202ac6",
"package_config_rev": "@0.1.3",
"path_tag": "@1.3.6",
"ply_rev": "@604b32590ffad5cbb82e4afef1d305512d06ae93",
"plugin_tag": "@0.1.0",
"ply_rev": "@604b32590ffad5cbb82e4afef1d305512d06ae93",
"pool_tag": "@1.2.1",
"protobuf_tag": "@0.5.1+1",
"pub_rev": "@217fc8ae2bdee58ebf4b11a6fa3d49624d90c0c4",
"pub_cache_tag": "@v0.1.0",
"pub_rev": "@217fc8ae2bdee58ebf4b11a6fa3d49624d90c0c4",
"pub_semver_tag": "@1.2.1",
"quiver_tag": "@0.21.4",
"resource_rev":"@a49101ba2deb29c728acba6fb86000a8f730f4b1",
"root_certificates_rev": "@aed07942ce98507d2be28cbd29e879525410c7fc",
"scheduled_test_tag": "@0.12.5+2",
"shelf_tag": "@0.6.5",
"smoke_rev" : "@f3361191cc2a85ebc1e4d4c33aec672d7915aba9",
"source_maps_tag": "@0.10.1",
"shelf_static_tag": "@0.2.3+1",
"shelf_tag": "@0.6.5",
"shelf_web_socket_tag": "@0.2.0",
"smoke_rev" : "@f3361191cc2a85ebc1e4d4c33aec672d7915aba9",
"source_map_stack_trace_tag": "@1.0.4",
"source_maps-0.9.4_rev": "@38524",
"source_maps_tag": "@0.10.1",
"source_span_tag": "@1.2.0",
"stack_trace_tag": "@1.4.2",
"stream_channel_tag": "@1.3.1",
"string_scanner_tag": "@0.1.4",
"sunflower_rev": "@879b704933413414679396b129f5dfa96f7a0b1e",
"test_tag": "@0.12.12",
"test_reflective_loader_tag": "@0.0.3",
"test_tag": "@0.12.12",
"typed_data_tag": "@1.1.2",
"utf_rev": "@1f55027068759e2d52f2c12de6a57cce5f3c5ee6",
"usage_rev": "@b5080dac0d26a5609b266f8fdb0d053bc4c1c638",
"utf_rev": "@1f55027068759e2d52f2c12de6a57cce5f3c5ee6",
"watcher_tag": "@0.9.7",
"when_tag": "@0.2.0+2",
"which_tag": "@0.1.3+1",
"web_components_rev": "@6349e09f9118dce7ae1b309af5763745e25a9d61",
"web_socket_channel_tag": "@1.0.0",
"WebCore_rev": "@a86fe28efadcfc781f836037a80f27e22a5dad17",
"when_tag": "@0.2.0+2",
"which_tag": "@0.1.3+1",
"yaml_tag": "@2.1.5",
"zlib_rev": "@c3d0a6190f2f8c924a05ab6cc97b8f975bddd33f",
"barback-0.13.0_rev": "@34853",
"barback-0.14.0_rev": "@36398",
"barback-0.14.1_rev": "@38525",
"source_maps-0.9.4_rev": "@38524",
}
deps = {
@ -182,6 +183,8 @@ deps = {
(Var("github_mirror") % "dev_compiler") + Var("dev_compiler_rev"),
Var("dart_root") + "/third_party/pkg/func":
(Var("github_dartlang") % "func") + Var("func_rev"),
Var("dart_root") + "/third_party/pkg/fixnum":
"https://github.com/dart-lang/fixnum.git" + Var("fixnum_tag"),
Var("dart_root") + "/third_party/pkg/glob":
(Var("github_mirror") % "glob") + Var("glob_rev"),
Var("dart_root") + "/third_party/pkg/html":

View file

@ -1,26 +0,0 @@
Copyright 2014, the Dart project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,22 +0,0 @@
fixnum
======
A fixed-size integer library for Dart.
- - -
The fixnum package provides data types for signed 32- and 64-bit integers.
The integer implementations in this library are designed to work identically
whether executed on the Dart VM or compiled to JavaScript.
Installing
----------
Use [pub](http://pub.dartlang.org) to install this package. Add the following
to your `pubspec.yaml` file:
dependencies:
fixnum: any
Then run `pub install`.
For more information, see the
[fixnum package on pub.dartlang.org](http://pub.dartlang.org/packages/fixnum).

View file

@ -1,19 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/**
* Signed 32- and 64-bit integer support.
*
* The integer implementations in this library are designed to work
* identically whether executed on the Dart VM or compiled to JavaScript.
*
* For information on installing and importing this library, see the
* [fixnum package on pub.dartlang.org]
* (http://pub.dartlang.org/packages/fixnum).
*/
library fixnum;
part 'src/intx.dart';
part 'src/int32.dart';
part 'src/int64.dart';

View file

@ -1,380 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of fixnum;
/**
* An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
* Arithmetic operations may overflow in order to maintain this range.
*/
class Int32 implements IntX {
/**
* The maximum positive value attainable by an [Int32], namely
* 2147483647.
*/
static const Int32 MAX_VALUE = const Int32._internal(0x7FFFFFFF);
/**
* The minimum positive value attainable by an [Int32], namely
* -2147483648.
*/
static const Int32 MIN_VALUE = const Int32._internal(-0x80000000);
/**
* An [Int32] constant equal to 0.
*/
static const Int32 ZERO = const Int32._internal(0);
/**
* An [Int32] constant equal to 1.
*/
static const Int32 ONE = const Int32._internal(1);
/**
* An [Int32] constant equal to 2.
*/
static const Int32 TWO = const Int32._internal(2);
// Hex digit char codes
static const int _CC_0 = 48; // '0'.codeUnitAt(0)
static const int _CC_9 = 57; // '9'.codeUnitAt(0)
static const int _CC_a = 97; // 'a'.codeUnitAt(0)
static const int _CC_z = 122; // 'z'.codeUnitAt(0)
static const int _CC_A = 65; // 'A'.codeUnitAt(0)
static const int _CC_Z = 90; // 'Z'.codeUnitAt(0)
static int _decodeDigit(int c) {
if (c >= _CC_0 && c <= _CC_9) {
return c - _CC_0;
} else if (c >= _CC_a && c <= _CC_z) {
return c - _CC_a + 10;
} else if (c >= _CC_A && c <= _CC_Z) {
return c - _CC_A + 10;
} else {
return -1; // bad char code
}
}
static int _validateRadix(int radix) {
if (2 <= radix && radix <= 36) return radix;
throw new RangeError.range(radix, 2, 36, 'radix');
}
/**
* Parses a [String] in a given [radix] between 2 and 16 and returns an
* [Int32].
*/
// TODO(rice) - Make this faster by converting several digits at once.
static Int32 parseRadix(String s, int radix) {
_validateRadix(radix);
Int32 x = ZERO;
for (int i = 0; i < s.length; i++) {
int c = s.codeUnitAt(i);
int digit = _decodeDigit(c);
if (digit < 0 || digit >= radix) {
throw new FormatException("Non-radix code unit: $c");
}
x = (x * radix) + digit;
}
return x;
}
/**
* Parses a decimal [String] and returns an [Int32].
*/
static Int32 parseInt(String s) => new Int32(int.parse(s));
/**
* Parses a hexadecimal [String] and returns an [Int32].
*/
static Int32 parseHex(String s) => parseRadix(s, 16);
// Assumes i is <= 32-bit.
static int _bitCount(int i) {
// See "Hacker's Delight", section 5-1, "Counting 1-Bits".
// The basic strategy is to use "divide and conquer" to
// add pairs (then quads, etc.) of bits together to obtain
// sub-counts.
//
// A straightforward approach would look like:
//
// i = (i & 0x55555555) + ((i >> 1) & 0x55555555);
// i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
// i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F);
// i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF);
// i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF);
//
// The code below removes unnecessary &'s and uses a
// trick to remove one instruction in the first line.
i -= ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = ((i + (i >> 4)) & 0x0F0F0F0F);
i += (i >> 8);
i += (i >> 16);
return (i & 0x0000003F);
}
// Assumes i is <= 32-bit
static int _numberOfLeadingZeros(int i) {
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
return _bitCount(~i);
}
static int _numberOfTrailingZeros(int i) => _bitCount((i & -i) - 1);
// The internal value, kept in the range [MIN_VALUE, MAX_VALUE].
final int _i;
const Int32._internal(int i) : _i = i;
/**
* Constructs an [Int32] from an [int]. Only the low 32 bits of the input
* are used.
*/
Int32([int i=0]) : _i = (i & 0x7fffffff) - (i & 0x80000000);
// Returns the [int] representation of the specified value. Throws
// [ArgumentError] for non-integer arguments.
int _toInt(val) {
if (val is Int32) {
return val._i;
} else if (val is int) {
return val;
}
throw new ArgumentError(val);
}
// The +, -, * , &, |, and ^ operaters deal with types as follows:
//
// Int32 + int => Int32
// Int32 + Int32 => Int32
// Int32 + Int64 => Int64
//
// The %, ~/ and remainder operators return an Int32 even with an Int64
// argument, since the result cannot be greater than the value on the
// left-hand side:
//
// Int32 % int => Int32
// Int32 % Int32 => Int32
// Int32 % Int64 => Int32
IntX operator +(other) {
if (other is Int64) {
return this.toInt64() + other;
}
return new Int32(_i + _toInt(other));
}
IntX operator -(other) {
if (other is Int64) {
return this.toInt64() - other;
}
return new Int32(_i - _toInt(other));
}
Int32 operator -() => new Int32(-_i);
IntX operator *(other) {
if (other is Int64) {
return this.toInt64() * other;
}
// TODO(rice) - optimize
return (this.toInt64() * other).toInt32();
}
Int32 operator %(other) {
if (other is Int64) {
// Result will be Int32
return (this.toInt64() % other).toInt32();
}
return new Int32(_i % _toInt(other));
}
Int32 operator ~/(other) {
if (other is Int64) {
return (this.toInt64() ~/ other).toInt32();
}
return new Int32(_i ~/ _toInt(other));
}
Int32 remainder(other) {
if (other is Int64) {
Int64 t = this.toInt64();
return (t - (t ~/ other) * other).toInt32();
}
return this - (this ~/ other) * other;
}
Int32 operator &(other) {
if (other is Int64) {
return (this.toInt64() & other).toInt32();
}
return new Int32(_i & _toInt(other));
}
Int32 operator |(other) {
if (other is Int64) {
return (this.toInt64() | other).toInt32();
}
return new Int32(_i | _toInt(other));
}
Int32 operator ^(other) {
if (other is Int64) {
return (this.toInt64() ^ other).toInt32();
}
return new Int32(_i ^ _toInt(other));
}
Int32 operator ~() => new Int32(~_i);
Int32 operator <<(int n) {
if (n < 0) {
throw new ArgumentError(n);
}
n &= 31;
return new Int32(_i << n);
}
Int32 operator >>(int n) {
if (n < 0) {
throw new ArgumentError(n);
}
n &= 31;
int value;
if (_i >= 0) {
value = _i >> n;
} else {
value = (_i >> n) | (0xffffffff << (32 - n));
}
return new Int32(value);
}
Int32 shiftRightUnsigned(int n) {
if (n < 0) {
throw new ArgumentError(n);
}
n &= 31;
int value;
if (_i >= 0) {
value = _i >> n;
} else {
value = (_i >> n) & ((1 << (32 - n)) - 1);
}
return new Int32(value);
}
/**
* Returns [:true:] if this [Int32] has the same numeric value as the
* given object. The argument may be an [int] or an [IntX].
*/
bool operator ==(other) {
if (other is Int32) {
return _i == other._i;
} else if (other is Int64) {
return this.toInt64() == other;
} else if (other is int) {
return _i == other;
}
return false;
}
int compareTo(IntX other) {
if (other is Int64) {
return this.toInt64().compareTo(other);
}
return _i.compareTo(_toInt(other));
}
bool operator <(other) {
if (other is Int64) {
return this.toInt64() < other;
}
return _i < _toInt(other);
}
bool operator <=(other) {
if (other is Int64) {
return this.toInt64() <= other;
}
return _i <= _toInt(other);
}
bool operator >(other) {
if (other is Int64) {
return this.toInt64() > other;
}
return _i > _toInt(other);
}
bool operator >=(other) {
if (other is Int64) {
return this.toInt64() >= other;
}
return _i >= _toInt(other);
}
bool get isEven => (_i & 0x1) == 0;
bool get isMaxValue => _i == 2147483647;
bool get isMinValue => _i == -2147483648;
bool get isNegative => _i < 0;
bool get isOdd => (_i & 0x1) == 1;
bool get isZero => _i == 0;
int get bitLength => _i.bitLength;
int get hashCode => _i;
Int32 abs() => _i < 0 ? new Int32(-_i) : this;
Int32 clamp(lowerLimit, upperLimit) {
if (this < lowerLimit) {
if (lowerLimit is IntX) return lowerLimit.toInt32();
if (lowerLimit is int) return new Int32(lowerLimit);
throw new ArgumentError(lowerLimit);
} else if (this > upperLimit) {
if (upperLimit is IntX) return upperLimit.toInt32();
if (upperLimit is int) return new Int32(upperLimit);
throw new ArgumentError(upperLimit);
}
return this;
}
int numberOfLeadingZeros() => _numberOfLeadingZeros(_i);
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);
Int32 toSigned(int width) {
if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32);
return new Int32(_i.toSigned(width));
}
Int32 toUnsigned(int width) {
if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32);
return new Int32(_i.toUnsigned(width));
}
List<int> toBytes() {
List<int> result = new List<int>(4);
result[0] = _i & 0xff;
result[1] = (_i >> 8) & 0xff;
result[2] = (_i >> 16) & 0xff;
result[3] = (_i >> 24) & 0xff;
return result;
}
double toDouble() => _i.toDouble();
int toInt() => _i;
Int32 toInt32() => this;
Int64 toInt64() => new Int64(_i);
String toString() => _i.toString();
String toHexString() => _i.toRadixString(16);
String toRadixString(int radix) => _i.toRadixString(radix);
}

File diff suppressed because it is too large Load diff

View file

@ -1,235 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of fixnum;
/**
* A fixed-precision integer.
*/
abstract class IntX implements Comparable<IntX> {
/** Addition operator. */
IntX operator +(other);
/** Subtraction operator. */
IntX operator -(other);
/**
* Negate operator.
*
* Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow.
*/
IntX operator -();
/** Multiplication operator. */
IntX operator *(other);
/**
* Euclidean modulo operator.
*
* Returns the remainder of the euclidean division. The euclidean division
* of two integers `a` and `b` yields two integers `q` and `r` such that
* `a == b * q + r` and `0 <= r < a.abs()`.
*/
IntX operator %(other);
/** Truncating division operator. */
IntX operator ~/(other);
/**
* Returns the remainder of the truncating division of this integer by
* [other].
*/
IntX remainder(other);
/** Bitwise and operator. */
IntX operator &(other);
/** Bitwise or operator. */
IntX operator |(other);
/** Bitwise xor operator. */
IntX operator ^(other);
/** Bitwise negate operator. */
IntX operator ~();
/**
* Left bit-shift operator.
*
* Returns the result of shifting the bits of this integer by [shiftAmount]
* bits to the left. Low-order bits are filled with zeros.
*/
IntX operator <<(int shiftAmount);
/**
* Right bit-shift operator.
*
* Returns the result of shifting the bits of this integer by [shiftAmount]
* bits to the right. High-order bits are filled with zero in the case where
* this integer is positive, or one in the case where it is negative.
*/
IntX operator >>(int shiftAmount);
/**
* Unsigned right-shift operator.
*
* Returns the result of shifting the bits of this integer by [shiftAmount]
* bits to the right. High-order bits are filled with zeros.
*/
IntX shiftRightUnsigned(int shiftAmount);
/**
* Returns `true` if and only if [other] is an int or IntX equal in
* value to this integer.
*/
bool operator ==(other);
/** Relational less than operator. */
bool operator <(other);
/** Relational less than or equal to operator. */
bool operator <=(other);
/** Relational greater than operator. */
bool operator >(other);
/** Relational greater than or equal to operator. */
bool operator >=(other);
/** Returns `true` if and only if this integer is even. */
bool get isEven;
/**
* Returns `true` if and only if this integer is the maximum signed value
* that can be represented within its bit size.
*/
bool get isMaxValue;
/**
* Returns `true` if and only if this integer is the minimum signed value
* that can be represented within its bit size.
*/
bool get isMinValue;
/** Returns `true` if and only if this integer is less than zero. */
bool get isNegative;
/** Returns `true` if and only if this integer is odd. */
bool get isOdd;
/** Returns `true` if and only if this integer is zero. */
bool get isZero;
int get hashCode;
/** Returns the absolute value of this integer. */
IntX abs();
/** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */
IntX clamp(lowerLimit, upperLimit);
/**
* Returns the minimum number of bits required to store this integer.
*
* The number of bits excludes the sign bit, which gives the natural length
* for non-negative (unsigned) values. Negative values are complemented to
* return the bit position of the first bit that differs from the sign bit.
*
* To find the the number of bits needed to store the value as a signed value,
* add one, i.e. use `x.bitLength + 1`.
*/
int get bitLength;
/**
* Returns the number of high-order zeros in this integer's bit
* representation.
*/
int numberOfLeadingZeros();
/**
* Returns the number of low-order zeros in this integer's bit representation.
*/
int numberOfTrailingZeros();
/**
* Returns the least significant [width] bits of this integer, extending the
* highest retained bit to the sign. This is the same as truncating the value
* to fit in [width] bits using an signed 2-s complement representation. The
* returned value has the same bit value in all positions higher than [width].
*
* If the input value fits in [width] bits without truncation, the result is
* the same as the input. The minimum width needed to avoid truncation of `x`
* is `x.bitLength + 1`, i.e.
*
* x == x.toSigned(x.bitLength + 1);
*/
IntX toSigned(int width);
/**
* Returns the least significant [width] bits of this integer as a
* non-negative number (i.e. unsigned representation). The returned value has
* zeros in all bit positions higher than [width].
*
* If the input fits in [width] bits without truncation, the result is the
* same as the input. The minimum width needed to avoid truncation of `x` is
* given by `x.bitLength`, i.e.
*
* x == x.toUnsigned(x.bitLength);
*/
IntX toUnsigned(int width);
/**
* Returns a byte-sequence representation of this integer.
*
* Returns a list of int, starting with the least significant byte.
*/
List<int> toBytes();
/**
* Returns the double representation of this integer.
*
* On some platforms, inputs with large absolute values (i.e., > 2^52) may
* lose some of their low-order bits.
*/
double toDouble();
/**
* Returns the int representation of this integer.
*
* On some platforms, inputs with large absolute values (i.e., > 2^52) may
* lose some of their low-order bits.
*/
int toInt();
/**
* Returns an Int32 representation of this integer.
*
* Narrower values are sign-extended and wider values have their high bits
* truncated.
*/
Int32 toInt32();
/** Returns an Int64 representation of this integer. */
Int64 toInt64();
/**
* Returns a string representing the value of this integer in decimal
* notation; example: `'13'`.
*/
String toString();
/**
* Returns a string representing the value of this integer in hexadecimal
* notation; example: `'0xd'`.
*/
String toHexString();
/**
* Returns a string representing the value of this integer in the given radix.
*
* [radix] must be an integer in the range 2 .. 16, inclusive.
*/
String toRadixString(int radix);
}

View file

@ -1,9 +0,0 @@
name: fixnum
version: 0.10.3
author: Dart Team <misc@dartlang.org>
description: Library for 32- and 64-bit fixed size integers.
homepage: http://www.dartlang.org
dev_dependencies:
unittest: ">=0.9.0 <0.10.0"
environment:
sdk: ">=0.8.10+6 <2.0.0"

View file

@ -1,365 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library Int32test;
import 'package:fixnum/fixnum.dart';
import 'package:unittest/unittest.dart';
void main() {
group("isX tests", () {
test("isEven", () {
expect((-Int32.ONE).isEven, false);
expect(Int32.ZERO.isEven, true);
expect(Int32.ONE.isEven, false);
expect(Int32.TWO.isEven, true);
});
test("isMaxValue", () {
expect(Int32.MIN_VALUE.isMaxValue, false);
expect(Int32.ZERO.isMaxValue, false);
expect(Int32.MAX_VALUE.isMaxValue, true);
});
test("isMinValue", () {
expect(Int32.MIN_VALUE.isMinValue, true);
expect(Int32.ZERO.isMinValue, false);
expect(Int32.MAX_VALUE.isMinValue, false);
});
test("isNegative", () {
expect(Int32.MIN_VALUE.isNegative, true);
expect(Int32.ZERO.isNegative, false);
expect(Int32.ONE.isNegative, false);
});
test("isOdd", () {
expect((-Int32.ONE).isOdd, true);
expect(Int32.ZERO.isOdd, false);
expect(Int32.ONE.isOdd, true);
expect(Int32.TWO.isOdd, false);
});
test("isZero", () {
expect(Int32.MIN_VALUE.isZero, false);
expect(Int32.ZERO.isZero, true);
expect(Int32.MAX_VALUE.isZero, false);
});
test("bitLength", () {
expect(new Int32(-2).bitLength, 1);
expect((-Int32.ONE).bitLength, 0);
expect(Int32.ZERO.bitLength, 0);
expect(Int32.ONE.bitLength, 1);
expect(new Int32(2).bitLength, 2);
expect(Int32.MAX_VALUE.bitLength, 31);
expect(Int32.MIN_VALUE.bitLength, 31);
});
});
group("arithmetic operators", () {
Int32 n1 = new Int32(1234);
Int32 n2 = new Int32(9876);
Int32 n3 = new Int32(-1234);
Int32 n4 = new Int32(-9876);
test("+", () {
expect(n1 + n2, new Int32(11110));
expect(n3 + n2, new Int32(8642));
expect(n3 + n4, new Int32(-11110));
expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE);
expect(() => new Int32(17) + null, throws);
});
test("-", () {
expect(n1 - n2, new Int32(-8642));
expect(n3 - n2, new Int32(-11110));
expect(n3 - n4, new Int32(8642));
expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE);
expect(() => new Int32(17) - null, throws);
});
test("unary -", () {
expect(-n1, new Int32(-1234));
expect(-Int32.ZERO, Int32.ZERO);
});
test("*", () {
expect(n1 * n2, new Int32(12186984));
expect(n2 * n3, new Int32(-12186984));
expect(n3 * n3, new Int32(1522756));
expect(n3 * n2, new Int32(-12186984));
expect(new Int32(0x12345678) * new Int32(0x22222222),
new Int32(-899716112));
expect((new Int32(123456789) * new Int32(987654321)),
new Int32(-67153019));
expect(new Int32(0x12345678) * new Int64(0x22222222),
new Int64.fromInts(0x026D60DC, 0xCA5F6BF0));
expect((new Int32(123456789) * 987654321),
new Int32(-67153019));
expect(() => new Int32(17) * null, throws);
});
test("~/", () {
expect(new Int32(829893893) ~/ new Int32(1919), new Int32(432461));
expect(new Int32(0x12345678) ~/ new Int32(0x22),
new Int32(0x12345678 ~/ 0x22));
expect(new Int32(829893893) ~/ new Int64(1919), new Int32(432461));
expect(new Int32(0x12345678) ~/ new Int64(0x22),
new Int32(0x12345678 ~/ 0x22));
expect(new Int32(829893893) ~/ 1919, new Int32(432461));
expect(() => new Int32(17) ~/ Int32.ZERO, throws);
expect(() => new Int32(17) ~/ null, throws);
});
test("%", () {
expect(new Int32(0x12345678) % new Int32(0x22),
new Int32(0x12345678 % 0x22));
expect(new Int32(0x12345678) % new Int64(0x22),
new Int32(0x12345678 % 0x22));
expect(() => new Int32(17) % null, throws);
});
test("remainder", () {
expect(new Int32(0x12345678).remainder(new Int32(0x22)),
new Int32(0x12345678.remainder(0x22)));
expect(new Int32(0x12345678).remainder(new Int32(-0x22)),
new Int32(0x12345678.remainder(-0x22)));
expect(new Int32(-0x12345678).remainder(new Int32(-0x22)),
new Int32(-0x12345678.remainder(-0x22)));
expect(new Int32(-0x12345678).remainder(new Int32(0x22)),
new Int32(-0x12345678.remainder(0x22)));
expect(new Int32(0x12345678).remainder(new Int64(0x22)),
new Int32(0x12345678.remainder(0x22)));
expect(() => new Int32(17).remainder(null), throws);
});
test("clamp", () {
Int32 val = new Int32(17);
expect(val.clamp(20, 30), new Int32(20));
expect(val.clamp(10, 20), new Int32(17));
expect(val.clamp(10, 15), new Int32(15));
expect(val.clamp(new Int32(20), new Int32(30)), new Int32(20));
expect(val.clamp(new Int32(10), new Int32(20)), new Int32(17));
expect(val.clamp(new Int32(10), new Int32(15)), new Int32(15));
expect(val.clamp(new Int64(20), new Int64(30)), new Int32(20));
expect(val.clamp(new Int64(10), new Int64(20)), new Int32(17));
expect(val.clamp(new Int64(10), new Int64(15)), new Int32(15));
expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int32(17));
expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int32(17));
expect(() => val.clamp(1, 'b'), throwsA(isArgumentError));
expect(() => val.clamp('a', 1), throwsA(isArgumentError));
});
});
group("comparison operators", () {
test("<", () {
expect(new Int32(17) < new Int32(18), true);
expect(new Int32(17) < new Int32(17), false);
expect(new Int32(17) < new Int32(16), false);
expect(new Int32(17) < new Int64(18), true);
expect(new Int32(17) < new Int64(17), false);
expect(new Int32(17) < new Int64(16), false);
expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false);
expect(() => new Int32(17) < null, throws);
});
test("<=", () {
expect(new Int32(17) <= new Int32(18), true);
expect(new Int32(17) <= new Int32(17), true);
expect(new Int32(17) <= new Int32(16), false);
expect(new Int32(17) <= new Int64(18), true);
expect(new Int32(17) <= new Int64(17), true);
expect(new Int32(17) <= new Int64(16), false);
expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false);
expect(() => new Int32(17) <= null, throws);
});
test("==", () {
expect(new Int32(17) == new Int32(18), false);
expect(new Int32(17) == new Int32(17), true);
expect(new Int32(17) == new Int32(16), false);
expect(new Int32(17) == new Int64(18), false);
expect(new Int32(17) == new Int64(17), true);
expect(new Int32(17) == new Int64(16), false);
expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false);
expect(new Int32(17) == new Object(), false);
expect(new Int32(17) == null, false);
});
test(">=", () {
expect(new Int32(17) >= new Int32(18), false);
expect(new Int32(17) >= new Int32(17), true);
expect(new Int32(17) >= new Int32(16), true);
expect(new Int32(17) >= new Int64(18), false);
expect(new Int32(17) >= new Int64(17), true);
expect(new Int32(17) >= new Int64(16), true);
expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true);
expect(() => new Int32(17) >= null, throws);
});
test(">", () {
expect(new Int32(17) > new Int32(18), false);
expect(new Int32(17) > new Int32(17), false);
expect(new Int32(17) > new Int32(16), true);
expect(new Int32(17) > new Int64(18), false);
expect(new Int32(17) > new Int64(17), false);
expect(new Int32(17) > new Int64(16), true);
expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true);
expect(() => new Int32(17) > null, throws);
});
});
group("bitwise operators", () {
test("&", () {
expect(new Int32(0x12345678) & new Int32(0x22222222),
new Int32(0x12345678 & 0x22222222));
expect(new Int32(0x12345678) & new Int64(0x22222222),
new Int64(0x12345678 & 0x22222222));
expect(() => new Int32(17) & null, throwsArgumentError);
});
test("|", () {
expect(new Int32(0x12345678) | new Int32(0x22222222),
new Int32(0x12345678 | 0x22222222));
expect(new Int32(0x12345678) | new Int64(0x22222222),
new Int64(0x12345678 | 0x22222222));
expect(() => new Int32(17) | null, throws);
});
test("^", () {
expect(new Int32(0x12345678) ^ new Int32(0x22222222),
new Int32(0x12345678 ^ 0x22222222));
expect(new Int32(0x12345678) ^ new Int64(0x22222222),
new Int64(0x12345678 ^ 0x22222222));
expect(() => new Int32(17) ^ null, throws);
});
test("~", () {
expect(~(new Int32(0x12345678)), new Int32(~0x12345678));
expect(-(new Int32(0x12345678)), new Int64(-0x12345678));
});
});
group("bitshift operators", () {
test("<<", () {
expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7));
expect(() => new Int32(17) << -1, throwsArgumentError);
expect(() => new Int32(17) << null, throws);
});
test(">>", () {
expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7));
expect(() => new Int32(17) >> -1, throwsArgumentError);
expect(() => new Int32(17) >> null, throws);
});
test("shiftRightUnsigned", () {
expect(new Int32(0x12345678).shiftRightUnsigned(7),
new Int32(0x12345678 >> 7));
expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
expect(() => (new Int32(17).shiftRightUnsigned(null)), throws);
});
});
group("conversions", () {
test("toSigned", () {
expect(Int32.ONE.toSigned(2), Int32.ONE);
expect(Int32.ONE.toSigned(1), -Int32.ONE);
expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE);
expect(Int32.MIN_VALUE.toSigned(32), Int32.MIN_VALUE);
expect(Int32.MAX_VALUE.toSigned(31), -Int32.ONE);
expect(Int32.MIN_VALUE.toSigned(31), Int32.ZERO);
expect(() => Int32.ONE.toSigned(0), throwsRangeError);
expect(() => Int32.ONE.toSigned(33), throwsRangeError);
});
test("toUnsigned", () {
expect(Int32.ONE.toUnsigned(1), Int32.ONE);
expect(Int32.ONE.toUnsigned(0), Int32.ZERO);
expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE);
expect(Int32.MIN_VALUE.toUnsigned(32), Int32.MIN_VALUE);
expect(Int32.MAX_VALUE.toUnsigned(31), Int32.MAX_VALUE);
expect(Int32.MIN_VALUE.toUnsigned(31), Int32.ZERO);
expect(() => Int32.ONE.toUnsigned(-1), throwsRangeError);
expect(() => Int32.ONE.toUnsigned(33), throwsRangeError);
});
test("toDouble", () {
expect(new Int32(17).toDouble(), same(17.0));
expect(new Int32(-17).toDouble(), same(-17.0));
});
test("toInt", () {
expect(new Int32(17).toInt(), 17);
expect(new Int32(-17).toInt(), -17);
});
test("toInt32", () {
expect(new Int32(17).toInt32(), new Int32(17));
expect(new Int32(-17).toInt32(), new Int32(-17));
});
test("toInt64", () {
expect(new Int32(17).toInt64(), new Int64(17));
expect(new Int32(-17).toInt64(), new Int64(-17));
});
});
group("parse", () {
test("base 10", () {
checkInt(int x) {
expect(Int32.parseRadix('$x', 10), new Int32(x));
}
checkInt(0);
checkInt(1);
checkInt(1000);
checkInt(12345678);
checkInt(2147483647);
checkInt(2147483648);
checkInt(4294967295);
checkInt(4294967296);
expect(() => Int32.parseRadix('xyzzy', -1), throwsArgumentError);
expect(() => Int32.parseRadix('plugh', 10),
throwsA(new isInstanceOf<FormatException>()));
});
test("parseRadix", () {
check(String s, int r, String x) {
expect(Int32.parseRadix(s, r).toString(), x);
}
check('deadbeef', 16, '-559038737');
check('95', 12, '113');
});
});
group("string representation", () {
test("toString", () {
expect(new Int32(0).toString(), "0");
expect(new Int32(1).toString(), "1");
expect(new Int32(-1).toString(), "-1");
expect(new Int32(1000).toString(), "1000");
expect(new Int32(-1000).toString(), "-1000");
expect(new Int32(123456789).toString(), "123456789");
expect(new Int32(2147483647).toString(), "2147483647");
expect(new Int32(2147483648).toString(), "-2147483648");
expect(new Int32(2147483649).toString(), "-2147483647");
expect(new Int32(2147483650).toString(), "-2147483646");
expect(new Int32(-2147483648).toString(), "-2147483648");
expect(new Int32(-2147483649).toString(), "2147483647");
expect(new Int32(-2147483650).toString(), "2147483646");
});
});
group("toHexString", () {
test("returns hexadecimal string representation", () {
expect(new Int32(-1).toHexString(), "-1");
expect((new Int32(-1) >> 8).toHexString(), "-1");
expect((new Int32(-1) << 8).toHexString(), "-100");
expect(new Int32(123456789).toHexString(), "75bcd15");
expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff");
});
});
group("toRadixString", () {
test("returns base n string representation", () {
expect(new Int32(123456789).toRadixString(5), "223101104124");
});
});
}

View file

@ -1,773 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library int64test;
import 'package:fixnum/fixnum.dart';
import 'package:unittest/unittest.dart';
void main() {
argumentErrorTest(name, op, [receiver = Int64.ONE]) {
throwsArgumentErrorMentioning(substring) =>
throwsA((e) => e is ArgumentError && '$e'.contains(substring));
expect(() => op(receiver, null), throwsArgumentErrorMentioning('null'));
expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"'));
}
group("is-tests", () {
test("isEven", () {
expect((-Int64.ONE).isEven, false);
expect(Int64.ZERO.isEven, true);
expect(Int64.ONE.isEven, false);
expect(Int64.TWO.isEven, true);
});
test("isMaxValue", () {
expect(Int64.MIN_VALUE.isMaxValue, false);
expect(Int64.ZERO.isMaxValue, false);
expect(Int64.MAX_VALUE.isMaxValue, true);
});
test("isMinValue", () {
expect(Int64.MIN_VALUE.isMinValue, true);
expect(Int64.ZERO.isMinValue, false);
expect(Int64.MAX_VALUE.isMinValue, false);
});
test("isNegative", () {
expect(Int64.MIN_VALUE.isNegative, true);
expect(Int64.ZERO.isNegative, false);
expect(Int64.ONE.isNegative, false);
});
test("isOdd", () {
expect((-Int64.ONE).isOdd, true);
expect(Int64.ZERO.isOdd, false);
expect(Int64.ONE.isOdd, true);
expect(Int64.TWO.isOdd, false);
});
test("isZero", () {
expect(Int64.MIN_VALUE.isZero, false);
expect(Int64.ZERO.isZero, true);
expect(Int64.MAX_VALUE.isZero, false);
});
test("bitLength", () {
expect(new Int64(-2).bitLength, 1);
expect((-Int64.ONE).bitLength, 0);
expect(Int64.ZERO.bitLength, 0);
expect((Int64.ONE << 21).bitLength, 22);
expect((Int64.ONE << 22).bitLength, 23);
expect((Int64.ONE << 43).bitLength, 44);
expect((Int64.ONE << 44).bitLength, 45);
expect(new Int64(2).bitLength, 2);
expect(Int64.MAX_VALUE.bitLength, 63);
expect(Int64.MIN_VALUE.bitLength, 63);
});
});
group("arithmetic operators", () {
Int64 n1 = new Int64(1234);
Int64 n2 = new Int64(9876);
Int64 n3 = new Int64(-1234);
Int64 n4 = new Int64(-9876);
Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd);
Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444);
test("+", () {
expect(n1 + n2, new Int64(11110));
expect(n3 + n2, new Int64(8642));
expect(n3 + n4, new Int64(-11110));
expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011));
expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE);
argumentErrorTest("+", (a, b) => a + b);
});
test("-", () {
expect(n1 - n2, new Int64(-8642));
expect(n3 - n2, new Int64(-11110));
expect(n3 - n4, new Int64(8642));
expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789));
expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE);
argumentErrorTest("-", (a, b) => a - b);
});
test("unary -", () {
expect(-n1, new Int64(-1234));
expect(-Int64.ZERO, Int64.ZERO);
});
test("*", () {
expect(new Int64(1111) * new Int64(3), new Int64(3333));
expect(new Int64(1111) * new Int64(-3), new Int64(-3333));
expect(new Int64(-1111) * new Int64(3), new Int64(-3333));
expect(new Int64(-1111) * new Int64(-3), new Int64(3333));
expect(new Int64(100) * Int64.ZERO, Int64.ZERO);
expect(new Int64.fromInts(0x12345678, 0x12345678) *
new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
expect(new Int64.fromInts(0xf2345678, 0x12345678) *
new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
expect(new Int64.fromInts(0xf2345678, 0x12345678) *
new Int64.fromInts(0xffff1234, 0x12345678),
new Int64.fromInts(0x297e3f7c, 0x1df4d840));
// RHS Int32
expect((new Int64(123456789) * new Int32(987654321)),
new Int64.fromInts(0x1b13114, 0xfbff5385));
expect((new Int64(123456789) * new Int32(987654321)),
new Int64.fromInts(0x1b13114, 0xfbff5385));
// Wraparound
expect((new Int64(123456789) * new Int64(987654321)),
new Int64.fromInts(0x1b13114, 0xfbff5385));
expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO);
expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE);
expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE);
argumentErrorTest("*", (a, b) => a * b);
});
test("~/", () {
Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF);
Int64 ten = new Int64(10);
expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5));
expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO);
expect(Int64.MAX_VALUE ~/ Int64.TWO,
new Int64.fromInts(0x3fffffff, 0xffffffff));
expect(Int64.ZERO ~/ new Int64(1000), Int64.ZERO);
expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE);
expect(new Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO);
expect(Int64.MIN_VALUE ~/ new Int64(8192), new Int64(-1125899906842624));
expect(Int64.MIN_VALUE ~/ new Int64(8193), new Int64(-1125762484664320));
expect(new Int64(-1000) ~/ new Int64(8192), Int64.ZERO);
expect(new Int64(-1000) ~/ new Int64(8193), Int64.ZERO);
expect(new Int64(-1000000000) ~/ new Int64(8192), new Int64(-122070));
expect(new Int64(-1000000000) ~/ new Int64(8193), new Int64(-122055));
expect(new Int64(1000000000) ~/ new Int64(8192), new Int64(122070));
expect(new Int64(1000000000) ~/ new Int64(8193), new Int64(122055));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400),
new Int64.fromInts(0x1fffff, 0xffffffff));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000),
new Int64.fromInts(0x1fff, 0xffffffff));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000),
new Int64.fromInts(0x1f, 0xffffffff));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000),
new Int64(536870911));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000),
new Int64(2097151));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000),
new Int64(8191));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000),
new Int64(31));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300),
new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000),
new Int64.fromInts(0x2, 0xAAAAAAAA));
expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000),
new Int64(0x2AA));
expect(Int64.MAX_VALUE ~/ new Int64(0x123456),
new Int64.fromInts(0x708, 0x002E9501));
expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9));
expect(new Int64(5) ~/ new Int64(5), Int64.ONE);
expect(new Int64(1000) ~/ new Int64(3), new Int64(333));
expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333));
expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333));
expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333));
expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO);
expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/
new Int64.fromInts(0x0, 0x123),
new Int64.fromInts(0x1003d0, 0xe84f5ae8));
expect(new Int64.fromInts(0x12345678, 0x12345678) ~/
new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x0, 0x10003));
expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/
new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0xffffffff, 0xffff3dfe));
expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/
new Int64.fromInts(0xffff1234, 0x12345678),
new Int64.fromInts(0x0, 0xeda));
expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461));
expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461));
expect(new Int64(829893893) ~/ 1919, new Int32(432461));
expect(() => new Int64(1) ~/ Int64.ZERO,
throwsA(new isInstanceOf<IntegerDivisionByZeroException>()));
expect(Int64.MIN_VALUE ~/ new Int64(2),
new Int64.fromInts(0xc0000000, 0x00000000));
expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE);
expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE);
expect(() => new Int64(17) ~/ Int64.ZERO, throws);
argumentErrorTest("~/", (a, b) => a ~/ b);
});
test("%", () {
// Define % as Euclidean mod, with positive result for all arguments
expect(Int64.ZERO % new Int64(1000), Int64.ZERO);
expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO);
expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000));
expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO);
expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145));
expect(new Int64(-1000) % new Int64(8192), new Int64(7192));
expect(new Int64(-1000) % new Int64(8193), new Int64(7193));
expect(new Int64(-1000000000) % new Int64(8192), new Int64(5632));
expect(new Int64(-1000000000) % new Int64(8193), new Int64(4808));
expect(new Int64(1000000000) % new Int64(8192), new Int64(2560));
expect(new Int64(1000000000) % new Int64(8193), new Int64(3385));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400),
new Int64.fromInts(0x0, 0x3ff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000),
new Int64.fromInts(0x0, 0x3ffff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000),
new Int64.fromInts(0x0, 0x3ffffff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000),
new Int64.fromInts(0x3, 0xffffffff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000),
new Int64.fromInts(0x3ff, 0xffffffff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000),
new Int64.fromInts(0x3ffff, 0xffffffff));
expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000),
new Int64.fromInts(0x3ffffff, 0xffffffff));
expect(new Int64(0x12345678).remainder(new Int64(0x22)),
new Int64(0x12345678.remainder(0x22)));
expect(new Int64(0x12345678).remainder(new Int64(-0x22)),
new Int64(0x12345678.remainder(-0x22)));
expect(new Int64(-0x12345678).remainder(new Int64(-0x22)),
new Int64(-0x12345678.remainder(-0x22)));
expect(new Int64(-0x12345678).remainder(new Int64(0x22)),
new Int64(-0x12345678.remainder(0x22)));
expect(new Int32(0x12345678).remainder(new Int64(0x22)),
new Int64(0x12345678.remainder(0x22)));
argumentErrorTest("%", (a, b) => a % b);
});
test("clamp", () {
Int64 val = new Int64(17);
expect(val.clamp(20, 30), new Int64(20));
expect(val.clamp(10, 20), new Int64(17));
expect(val.clamp(10, 15), new Int64(15));
expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20));
expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17));
expect(val.clamp(new Int32(10), new Int32(15)), new Int64(15));
expect(val.clamp(new Int64(20), new Int64(30)), new Int64(20));
expect(val.clamp(new Int64(10), new Int64(20)), new Int64(17));
expect(val.clamp(new Int64(10), new Int64(15)), new Int64(15));
expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int64(17));
expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int64(17));
expect(() => val.clamp(1, 'b'), throwsA(isArgumentError));
expect(() => val.clamp('a', 1), throwsA(isArgumentError));
});
});
group("comparison operators", () {
Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0);
Int64 largePos = new Int64.fromInts(0x12341234, 0x0);
Int64 largePosPlusOne = largePos + new Int64(1);
test("<", () {
expect(new Int64(10) < new Int64(11), true);
expect(new Int64(10) < new Int64(10), false);
expect(new Int64(10) < new Int64(9), false);
expect(new Int64(10) < new Int32(11), true);
expect(new Int64(10) < new Int32(10), false);
expect(new Int64(10) < new Int32(9), false);
expect(new Int64(-10) < new Int64(-11), false);
expect(Int64.MIN_VALUE < Int64.ZERO, true);
expect(largeNeg < largePos, true);
expect(largePos < largePosPlusOne, true);
expect(largePos < largePos, false);
expect(largePosPlusOne < largePos, false);
expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false);
argumentErrorTest("<", (a, b) => a < b);
});
test("<=", () {
expect(new Int64(10) <= new Int64(11), true);
expect(new Int64(10) <= new Int64(10), true);
expect(new Int64(10) <= new Int64(9), false);
expect(new Int64(10) <= new Int32(11), true);
expect(new Int64(10) <= new Int32(10), true);
expect(new Int64(10) <= new Int64(9), false);
expect(new Int64(-10) <= new Int64(-11), false);
expect(new Int64(-10) <= new Int64(-10), true);
expect(largeNeg <= largePos, true);
expect(largePos <= largeNeg, false);
expect(largePos <= largePosPlusOne, true);
expect(largePos <= largePos, true);
expect(largePosPlusOne <= largePos, false);
expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false);
argumentErrorTest("<=", (a, b) => a <= b);
});
test("==", () {
expect(new Int64(10) == new Int64(11), false);
expect(new Int64(10) == new Int64(10), true);
expect(new Int64(10) == new Int64(9), false);
expect(new Int64(10) == new Int32(11), false);
expect(new Int64(10) == new Int32(10), true);
expect(new Int64(10) == new Int32(9), false);
expect(new Int64(-10) == new Int64(-10), true);
expect(new Int64(-10) != new Int64(-10), false);
expect(largePos == largePos, true);
expect(largePos == largePosPlusOne, false);
expect(largePosPlusOne == largePos, false);
expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false);
expect(new Int64(17) == new Object(), false);
expect(new Int64(17) == null, false);
});
test(">=", () {
expect(new Int64(10) >= new Int64(11), false);
expect(new Int64(10) >= new Int64(10), true);
expect(new Int64(10) >= new Int64(9), true);
expect(new Int64(10) >= new Int32(11), false);
expect(new Int64(10) >= new Int32(10), true);
expect(new Int64(10) >= new Int32(9), true);
expect(new Int64(-10) >= new Int64(-11), true);
expect(new Int64(-10) >= new Int64(-10), true);
expect(largePos >= largeNeg, true);
expect(largeNeg >= largePos, false);
expect(largePos >= largePosPlusOne, false);
expect(largePos >= largePos, true);
expect(largePosPlusOne >= largePos, true);
expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true);
argumentErrorTest(">=", (a, b) => a >= b);
});
test(">", () {
expect(new Int64(10) > new Int64(11), false);
expect(new Int64(10) > new Int64(10), false);
expect(new Int64(10) > new Int64(9), true);
expect(new Int64(10) > new Int32(11), false);
expect(new Int64(10) > new Int32(10), false);
expect(new Int64(10) > new Int32(9), true);
expect(new Int64(-10) > new Int64(-11), true);
expect(new Int64(10) > new Int64(-11), true);
expect(new Int64(-10) > new Int64(11), false);
expect(largePos > largeNeg, true);
expect(largeNeg > largePos, false);
expect(largePos > largePosPlusOne, false);
expect(largePos > largePos, false);
expect(largePosPlusOne > largePos, true);
expect(Int64.ZERO > Int64.MIN_VALUE, true);
expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true);
argumentErrorTest(">", (a, b) => a > b);
});
});
group("bitwise operators", () {
Int64 n1 = new Int64(1234);
Int64 n2 = new Int64(9876);
Int64 n3 = new Int64(-1234);
Int64 n4 = new Int64(0x1234) << 32;
Int64 n5 = new Int64(0x9876) << 32;
test("&", () {
expect(n1 & n2, new Int64(1168));
expect(n3 & n2, new Int64(8708));
expect(n4 & n5, new Int64(0x1034) << 32);
expect(() => n1 & null, throwsArgumentError);
argumentErrorTest("&", (a, b) => a & b);
});
test("|", () {
expect(n1 | n2, new Int64(9942));
expect(n3 | n2, new Int64(-66));
expect(n4 | n5, new Int64(0x9a76) << 32);
expect(() => n1 | null, throwsArgumentError);
argumentErrorTest("|", (a, b) => a | b);
});
test("^", () {
expect(n1 ^ n2, new Int64(8774));
expect(n3 ^ n2, new Int64(-8774));
expect(n4 ^ n5, new Int64(0x8a42) << 32);
expect(() => n1 ^ null, throwsArgumentError);
argumentErrorTest("^", (a, b) => a ^ b);
});
test("~", () {
expect(-new Int64(1), new Int64(-1));
expect(-new Int64(-1), new Int64(1));
expect(-Int64.MIN_VALUE, Int64.MIN_VALUE);
expect(~n1, new Int64(-1235));
expect(~n2, new Int64(-9877));
expect(~n3, new Int64(1233));
expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff));
expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff));
});
});
group("bitshift operators", () {
test("<<", () {
expect(new Int64.fromInts(0x12341234, 0x45674567) << 10,
new Int64.fromInts(0xd048d115, 0x9d159c00));
expect(new Int64.fromInts(0x92341234, 0x45674567) << 10,
new Int64.fromInts(0xd048d115, 0x9d159c00));
expect(new Int64(-1) << 5, new Int64(-32));
expect(new Int64(-1) << 0, new Int64(-1));
expect(() => new Int64(17) << -1, throwsArgumentError);
expect(() => new Int64(17) << null, throws);
});
test(">>", () {
expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624");
expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10,
new Int64.fromInts(0x48d04, 0x8d1159d1));
expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10,
new Int64.fromInts(0xffe48d04, 0x8d1159d1));
expect(new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34,
new Int64(67108863));
for (int n = 0; n <= 66; n++) {
expect(new Int64(-1) >> n, new Int64(-1));
}
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8,
new Int64.fromInts(0x00723456, 0x789abcde));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16,
new Int64.fromInts(0x00007234, 0x56789abc));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24,
new Int64.fromInts(0x00000072, 0x3456789a));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28,
new Int64.fromInts(0x00000007, 0x23456789));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32,
new Int64.fromInts(0x00000000, 0x72345678));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 36,
new Int64.fromInts(0x00000000, 0x07234567));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 40,
new Int64.fromInts(0x00000000, 0x00723456));
expect(new Int64.fromInts(0x72345678, 0x9abcde00) >> 44,
new Int64.fromInts(0x00000000, 0x00072345));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 48,
new Int64.fromInts(0x00000000, 0x00007234));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 8,
new Int64.fromInts(0xff923456, 0x789abcde));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 16,
new Int64.fromInts(0xffff9234, 0x56789abc));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 24,
new Int64.fromInts(0xffffff92, 0x3456789a));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 28,
new Int64.fromInts(0xfffffff9, 0x23456789));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32,
new Int64.fromInts(0xffffffff, 0x92345678));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36,
new Int64.fromInts(0xffffffff, 0xf9234567));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40,
new Int64.fromInts(0xffffffff, 0xff923456));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44,
new Int64.fromInts(0xffffffff, 0xfff92345));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48,
new Int64.fromInts(0xffffffff, 0xffff9234));
expect(() => new Int64(17) >> -1, throwsArgumentError);
expect(() => new Int64(17) >> null, throws);
});
test("shiftRightUnsigned", () {
expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10),
new Int64.fromInts(0x48d04, 0x8d1159d1));
expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10),
new Int64.fromInts(0x248d04, 0x8d1159d1));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8),
new Int64.fromInts(0x00723456, 0x789abcde));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16),
new Int64.fromInts(0x00007234, 0x56789abc));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24),
new Int64.fromInts(0x00000072, 0x3456789a));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28),
new Int64.fromInts(0x00000007, 0x23456789));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32),
new Int64.fromInts(0x00000000, 0x72345678));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36),
new Int64.fromInts(0x00000000, 0x07234567));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40),
new Int64.fromInts(0x00000000, 0x00723456));
expect(new Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44),
new Int64.fromInts(0x00000000, 0x00072345));
expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48),
new Int64.fromInts(0x00000000, 0x00007234));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8),
new Int64.fromInts(0x00923456, 0x789abcde));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16),
new Int64.fromInts(0x00009234, 0x56789abc));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24),
new Int64.fromInts(0x00000092, 0x3456789a));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28),
new Int64.fromInts(0x00000009, 0x23456789));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32),
new Int64.fromInts(0x00000000, 0x92345678));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36),
new Int64.fromInts(0x00000000, 0x09234567));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40),
new Int64.fromInts(0x00000000, 0x00923456));
expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44),
new Int64.fromInts(0x00000000, 0x00092345));
expect(new Int64.fromInts(0x00000000, 0x00009234),
new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48));
expect(() => new Int64(17).shiftRightUnsigned(-1),
throwsArgumentError);
expect(() => new Int64(17).shiftRightUnsigned(null), throws);
});
test("overflow", () {
expect((new Int64(1) << 63) >> 1,
-new Int64.fromInts(0x40000000, 0x00000000));
expect((new Int64(-1) << 32) << 32, new Int64(0));
expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE);
expect(Int64.MIN_VALUE << 1, new Int64(0));
expect((-new Int64.fromInts(8, 0)) >> 1,
new Int64.fromInts(0xfffffffc, 0x00000000));
expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1),
new Int64.fromInts(0x7ffffffc, 0x0));
});
});
group("conversions", () {
test("toSigned", () {
expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44);
expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44));
expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22);
expect((Int64.ONE << 22).toSigned(23), -(Int64.ONE << 22));
expect(Int64.ONE.toSigned(2), Int64.ONE);
expect(Int64.ONE.toSigned(1), -Int64.ONE);
expect(Int64.MAX_VALUE.toSigned(64), Int64.MAX_VALUE);
expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE);
expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE);
expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO);
expect(() => Int64.ONE.toSigned(0), throwsRangeError);
expect(() => Int64.ONE.toSigned(65), throwsRangeError);
});
test("toUnsigned", () {
expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44);
expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO);
expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22);
expect((Int64.ONE << 22).toUnsigned(22), Int64.ZERO);
expect(Int64.ONE.toUnsigned(1), Int64.ONE);
expect(Int64.ONE.toUnsigned(0), Int64.ZERO);
expect(Int64.MAX_VALUE.toUnsigned(64), Int64.MAX_VALUE);
expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE);
expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE);
expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO);
expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError);
expect(() => Int64.ONE.toUnsigned(65), throwsRangeError);
});
test("toDouble", () {
expect(new Int64(0).toDouble(), same(0.0));
expect(new Int64(100).toDouble(), same(100.0));
expect(new Int64(-100).toDouble(), same(-100.0));
expect(new Int64(2147483647).toDouble(), same(2147483647.0));
expect(new Int64(2147483648).toDouble(), same(2147483648.0));
expect(new Int64(-2147483647).toDouble(), same(-2147483647.0));
expect(new Int64(-2147483648).toDouble(), same(-2147483648.0));
expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0));
expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0));
expect(new Int64(-4503599627370495).toDouble(),
same(-4503599627370495.0));
expect(new Int64(-4503599627370496).toDouble(),
same(-4503599627370496.0));
expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1),
"-10000000000000000.0");
expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1),
"-10000000000000000.0");
expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1),
"-10000000000000002.0");
expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1),
"-10000000000000004.0");
expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1),
"-10000000000000004.0");
expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1),
"-10000000000000004.0");
expect(Int64.parseInt("-10000000000000006").toDouble().toStringAsFixed(1),
"-10000000000000006.0");
expect(Int64.parseInt("-10000000000000007").toDouble().toStringAsFixed(1),
"-10000000000000008.0");
expect(Int64.parseInt("-10000000000000008").toDouble().toStringAsFixed(1),
"-10000000000000008.0");
});
test("toInt", () {
expect(new Int64(0).toInt(), 0);
expect(new Int64(100).toInt(), 100);
expect(new Int64(-100).toInt(), -100);
expect(new Int64(2147483647).toInt(), 2147483647);
expect(new Int64(2147483648).toInt(), 2147483648);
expect(new Int64(-2147483647).toInt(), -2147483647);
expect(new Int64(-2147483648).toInt(), -2147483648);
expect(new Int64(4503599627370495).toInt(), 4503599627370495);
expect(new Int64(4503599627370496).toInt(), 4503599627370496);
expect(new Int64(-4503599627370495).toInt(), -4503599627370495);
expect(new Int64(-4503599627370496).toInt(), -4503599627370496);
expect(Int64.parseInt("-10000000000000000").toInt(),
same(-10000000000000000));
expect(Int64.parseInt("-10000000000000001").toInt(),
same(-10000000000000001));
expect(Int64.parseInt("-10000000000000002").toInt(),
same(-10000000000000002));
expect(Int64.parseInt("-10000000000000003").toInt(),
same(-10000000000000003));
expect(Int64.parseInt("-10000000000000004").toInt(),
same(-10000000000000004));
expect(Int64.parseInt("-10000000000000005").toInt(),
same(-10000000000000005));
expect(Int64.parseInt("-10000000000000006").toInt(),
same(-10000000000000006));
expect(Int64.parseInt("-10000000000000007").toInt(),
same(-10000000000000007));
expect(Int64.parseInt("-10000000000000008").toInt(),
same(-10000000000000008));
});
test("toInt32", () {
expect(new Int64(0).toInt32(), new Int32(0));
expect(new Int64(1).toInt32(), new Int32(1));
expect(new Int64(-1).toInt32(), new Int32(-1));
expect(new Int64(2147483647).toInt32(), new Int32(2147483647));
expect(new Int64(2147483648).toInt32(), new Int32(-2147483648));
expect(new Int64(2147483649).toInt32(), new Int32(-2147483647));
expect(new Int64(2147483650).toInt32(), new Int32(-2147483646));
expect(new Int64(-2147483648).toInt32(), new Int32(-2147483648));
expect(new Int64(-2147483649).toInt32(), new Int32(2147483647));
expect(new Int64(-2147483650).toInt32(), new Int32(2147483646));
expect(new Int64(-2147483651).toInt32(), new Int32(2147483645));
});
});
test("JavaScript 53-bit integer boundary", () {
Int64 _factorial(Int64 n) {
if (n.isZero) {
return new Int64(1);
} else {
return n * _factorial(n - new Int64(1));
}
}
Int64 fact18 = _factorial(new Int64(18));
Int64 fact17 = _factorial(new Int64(17));
expect(fact18 ~/ fact17, new Int64(18));
});
test("min, max values", () {
expect(new Int64(1) << 63, Int64.MIN_VALUE);
expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE);
});
group("parse", () {
test("parseRadix10", () {
checkInt(int x) {
expect(Int64.parseRadix('$x', 10), new Int64(x));
}
checkInt(0);
checkInt(1);
checkInt(-1);
checkInt(1000);
checkInt(12345678);
checkInt(-12345678);
checkInt(2147483647);
checkInt(2147483648);
checkInt(-2147483647);
checkInt(-2147483648);
checkInt(4294967295);
checkInt(4294967296);
checkInt(-4294967295);
checkInt(-4294967296);
});
test("parseRadix", () {
check(String s, int r, String x) {
expect(Int64.parseRadix(s, r).toString(), x);
}
check('ghoul', 36, '27699213');
check('ghoul', 35, '24769346');
// Min and max value.
check("-9223372036854775808", 10, "-9223372036854775808");
check("9223372036854775807", 10, "9223372036854775807");
// Overflow during parsing.
check("9223372036854775808", 10, "-9223372036854775808");
expect(() => Int64.parseRadix('0', 1), throwsRangeError);
expect(() => Int64.parseRadix('0', 37), throwsRangeError);
expect(() => Int64.parseRadix('xyzzy', -1), throwsRangeError);
expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException);
});
test("parseRadixN", () {
check(String s, int r) {
expect(Int64.parseRadix(s, r).toRadixString(r), s);
}
check("2ppp111222333", 33); // This value & radix requires three chunks.
});
});
group("string representation", () {
test("toString", () {
expect(new Int64(0).toString(), "0");
expect(new Int64(1).toString(), "1");
expect(new Int64(-1).toString(), "-1");
expect(new Int64(-10).toString(), "-10");
expect(Int64.MIN_VALUE.toString(), "-9223372036854775808");
expect(Int64.MAX_VALUE.toString(), "9223372036854775807");
int top = 922337201;
int bottom = 967490662;
Int64 fullnum = (new Int64(1000000000) * new Int64(top)) +
new Int64(bottom);
expect(fullnum.toString(), "922337201967490662");
expect((-fullnum).toString(), "-922337201967490662");
expect(new Int64(123456789).toString(), "123456789");
});
test("toHexString", () {
Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234);
expect(Int64.ZERO.toHexString(), "0");
expect(deadbeef12341234.toHexString(), "DEADBEEF12341234");
expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(),
"17678A7DEF01234");
expect(new Int64(123456789).toHexString(), "75BCD15");
});
test("toRadixString", () {
expect(new Int64(123456789).toRadixString(5), "223101104124");
expect(Int64.MIN_VALUE.toRadixString(2),
"-1000000000000000000000000000000000000000000000000000000000000000");
expect(Int64.MIN_VALUE.toRadixString(3),
"-2021110011022210012102010021220101220222");
expect(Int64.MIN_VALUE.toRadixString(4),
"-20000000000000000000000000000000");
expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213");
expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212");
expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301");
expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000");
expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828");
expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808");
expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698");
expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368");
expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38");
expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8");
expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808");
expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000");
expect(Int64.MAX_VALUE.toRadixString(2),
"111111111111111111111111111111111111111111111111111111111111111");
expect(Int64.MAX_VALUE.toRadixString(3),
"2021110011022210012102010021220101220221");
expect(Int64.MAX_VALUE.toRadixString(4),
"13333333333333333333333333333333");
expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212");
expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211");
expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300");
expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777");
expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827");
expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807");
expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697");
expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367");
expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37");
expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7");
expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807");
expect(() => Int64.ZERO.toRadixString(1), throwsRangeError);
expect(() => Int64.ZERO.toRadixString(37), throwsRangeError);
});
});
}