Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge in changes from SDK branch
Browse files Browse the repository at this point in the history
Includes performance fixes and error tests.

[email protected]

Review URL: https://codereview.chromium.org//1834783004 .
  • Loading branch information
rakudrama committed Apr 21, 2016
1 parent 7c6e8b4 commit b212014
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 167 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ 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.

## Installation

Use [pub](http://pub.dartlang.org) to install this package. Add the following
to your `pubspec.yaml` file:

dependencies:
fixnum: '>=0.9.1 <0.10.0'

For more information, see the
[fixnum package](http://pub.dartlang.org/packages/fixnum) on
[pub.dartlang.org](http://pub.dartlang.org).
13 changes: 8 additions & 5 deletions lib/src/int32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ class Int32 implements IntX {
}
}

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) {
if ((radix <= 1) || (radix > 16)) {
throw new ArgumentError("Bad radix: $radix");
}
_validateRadix(radix);
Int32 x = ZERO;
for (int i = 0; i < s.length; i++) {
int c = s.codeUnitAt(i);
Expand Down Expand Up @@ -348,12 +351,12 @@ class Int32 implements IntX {
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);

Int32 toSigned(int width) {
if (width < 1 || width > 32) throw new ArgumentError(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 ArgumentError(width);
if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32);
return new Int32(_i.toUnsigned(width));
}

Expand Down
Loading

0 comments on commit b212014

Please sign in to comment.