diff --git a/pkgs/fixnum/lib/src/int64_native.dart b/pkgs/fixnum/lib/src/int64_native.dart index b15bc99b..69bd4484 100644 --- a/pkgs/fixnum/lib/src/int64_native.dart +++ b/pkgs/fixnum/lib/src/int64_native.dart @@ -362,8 +362,8 @@ class Int64 implements IntX { throw ArgumentError('toStringRadixUnsigned radix must be >= 2 and <= 36' ' (found $radix)'); } - if (value == 0) { - return '0'; + if (value >= 0) { + return value.toRadixString(radix); } // Split value into two 32-bit unsigned digits (v1, v0). final v1 = value >>> 32; diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index e4bdd440..c711f19e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -1140,7 +1140,24 @@ void main() { }); test('toStringUnsigned', () { - List values = []; + expect(Int64.MAX_VALUE.toStringUnsigned(), '9223372036854775807'); + expect(Int32.MAX_VALUE.toInt64().toStringUnsigned(), '2147483647'); + expect(Int64(2).toStringUnsigned(), '2'); + expect(Int64(1).toStringUnsigned(), '1'); + expect(Int64(0).toStringUnsigned(), '0'); + expect(Int64(-1).toStringUnsigned(), '18446744073709551615'); + expect(Int64(-2).toStringUnsigned(), '18446744073709551614'); + expect( + Int32.MIN_VALUE.toInt64().toStringUnsigned(), '18446744071562067968'); + expect(Int64.MIN_VALUE.toStringUnsigned(), '9223372036854775808'); + + List values = [ + Int64.MAX_VALUE, + Int64(1), + Int64(0), + Int64(-1), + Int64.MIN_VALUE, + ]; for (int high = 0; high < 16; high++) { for (int low = -2; low <= 2; low++) { values.add((Int64(high) << (64 - 4)) + Int64(low));