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

Unified Diff: pkg/fixnum/lib/src/int32.dart

Issue 24388004: Added bitLength, clamp(), toDouble(), toSigned(), toUnsigned(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use string literals in place of doubles where precision is exceeded Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/fixnum/lib/src/int64.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fixnum/lib/src/int32.dart
diff --git a/pkg/fixnum/lib/src/int32.dart b/pkg/fixnum/lib/src/int32.dart
index a160058176e856c909bdb2783fb4bdba2b293cc0..c013f916085adae32fbb6d6f0a0ba50f615e36fd 100644
--- a/pkg/fixnum/lib/src/int32.dart
+++ b/pkg/fixnum/lib/src/int32.dart
@@ -332,14 +332,38 @@ class Int32 implements IntX {
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 ArgumentError(width);
+ return new Int32(_i.toSigned(width));
+ }
+
+ Int32 toUnsigned(int width) {
+ if (width < 0 || width > 32) throw new ArgumentError(width);
+ return new Int32(_i.toUnsigned(width));
+ }
+
List<int> toBytes() {
List<int> result = new List<int>(4);
result[0] = _i & 0xff;
@@ -349,6 +373,7 @@ class Int32 implements IntX {
return result;
}
+ double toDouble() => _i.toDouble();
int toInt() => _i;
Int32 toInt32() => this;
Int64 toInt64() => new Int64(_i);
« no previous file with comments | « no previous file | pkg/fixnum/lib/src/int64.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698