@@ -62,7 +62,7 @@ import 'package:meta/meta.dart';
62
62
/// important to be aware of this limitation.
63
63
///
64
64
/// This also applies to methods such as [List.cast] or [Iterable.whereType] .
65
- extension type const Int16 ._(int _) implements FixedInt {
65
+ extension type const Int16 ._(int _) implements int {
66
66
static const _descriptor = IntDescriptor <Int16 >.signed (
67
67
Int16 .fromUnchecked,
68
68
width: width,
@@ -72,6 +72,9 @@ extension type const Int16._(int _) implements FixedInt {
72
72
/// Always `0` .
73
73
static const zero = Int16 .fromUnchecked (0 );
74
74
75
+ /// Always `1` .
76
+ static const one = Int16 .fromUnchecked (1 );
77
+
75
78
/// The minimum value that this type can represent.
76
79
static const min = Int16 .fromUnchecked (- 32768 );
77
80
@@ -157,21 +160,6 @@ extension type const Int16._(int _) implements FixedInt {
157
160
@pragma ('vm:prefer-inline' )
158
161
factory Int16 .fromClamped (int v) => _descriptor.fitClamping (v);
159
162
160
- /// Defines an existing fixed-width integer [v] as a Int16.
161
- ///
162
- /// - If `this` 's width is >= [v] 's width, the result is the same as [v] .
163
- /// - Otherwise, the result is clamped to fit, similar to `fromClamped` .
164
- ///
165
- /// This is a convenience constructor; similar behavior can be achieved with:
166
- ///
167
- /// ```dart
168
- /// final rawInt = v.toInt();
169
- /// Int16.fromClamped(rawInt);
170
- /// ```
171
- @pragma ('dart2js:tryInline' )
172
- @pragma ('vm:prefer-inline' )
173
- factory Int16 .fromInt (FixedInt v) => _descriptor.fitClamping (v.toInt ());
174
-
175
163
/// Creates a [Int16] using two integers as high and low bits.
176
164
///
177
165
/// Each integer should be in the range of `0` to `2^(16 / 2) - 1` ;
@@ -708,6 +696,7 @@ extension type const Int16._(int _) implements FixedInt {
708
696
/// ```dart
709
697
/// Int16(-3).abs(); // 3
710
698
/// ```
699
+ @redeclare
711
700
Int16 abs () => Int16 (_.abs ());
712
701
713
702
/// Returns the absolute value of this integer.
@@ -774,6 +763,7 @@ extension type const Int16._(int _) implements FixedInt {
774
763
/// Int16(1).bitLength(); // 1
775
764
/// Int16(2).bitLength(); // 2
776
765
/// ```
766
+ @redeclare
777
767
int get bitLength => _.bitLength;
778
768
779
769
/// Whether this integer is the minimum value representable by this type.
@@ -782,26 +772,6 @@ extension type const Int16._(int _) implements FixedInt {
782
772
/// Whether this integer is the maximum value representable by this type.
783
773
bool get isMax => identical (_, max);
784
774
785
- /// Returns true if and only if this integer is even.
786
- ///
787
- /// ## Example
788
- ///
789
- /// ```dart
790
- /// Int16(2).isEven; // true
791
- /// Int16(3).isEven; // false
792
- /// ```
793
- bool get isEven => _.isEven;
794
-
795
- /// Returns true if and only if this integer is odd.
796
- ///
797
- /// ## Example
798
- ///
799
- /// ```dart
800
- /// Int16(2).isOdd; // false
801
- /// Int16(3).isOdd; // true
802
- /// ```
803
- bool get isOdd => _.isOdd;
804
-
805
775
/// Returns the sign of this integer.
806
776
///
807
777
/// Returns 0 for zero, -1 for values less than zero and +1 for values greater
@@ -814,41 +784,23 @@ extension type const Int16._(int _) implements FixedInt {
814
784
/// Int16(0).sign; // 0
815
785
/// Int16(3).sign; // 1
816
786
/// ```
787
+ @redeclare
817
788
Int16 get sign => Int16 .fromUnchecked (_.sign);
818
789
819
- /// Returns true if and only if this integer is zero.
820
- ///
821
- /// ## Example
822
- ///
823
- /// ```dart
824
- /// Int16(0).isZero; // true
825
- /// Int16(3).isZero; // false
826
- /// ```
827
- bool get isZero => _ == 0 ;
828
-
829
790
/// Returns true if and only if this integer is positive.
830
791
///
831
792
/// A positive integer is greater than zero.
832
- ///
833
- /// ## Example
834
- ///
835
- /// ```dart
836
- /// Int16(0).isPositive; // false
837
- /// Int16(3).isPositive; // true
838
- /// ```
839
793
bool get isPositive => _ > 0 ;
840
794
841
- /// Returns true if and only if this integer is negative.
842
- ///
843
- /// A negative integer is less than zero.
795
+ /// Returns true if and only if this integer is zero.
844
796
///
845
797
/// ## Example
846
798
///
847
799
/// ```dart
848
- /// Int16(-3).isNegative ; // true
849
- /// Int16(0).isNegative ; // false
800
+ /// Int16(0).isZero ; // true
801
+ /// Int16(3).isZero ; // false
850
802
/// ```
851
- bool get isNegative => _ < 0 ;
803
+ bool get isZero => _ == 0 ;
852
804
853
805
/// Returns `this` clamped to be in the range of [lowerLimit] and
854
806
/// [upperLimit] .
@@ -862,6 +814,7 @@ extension type const Int16._(int _) implements FixedInt {
862
814
/// Int16(4).clamp(Int16(3), Int16(5)); // 4
863
815
/// Int16(6).clamp(Int16(3), Int16(5)); // 5
864
816
/// ```
817
+ @redeclare
865
818
Int16 clamp (Int16 lowerLimit, Int16 upperLimit) {
866
819
return Int16 .fromUnchecked (_.clamp (lowerLimit._, upperLimit._));
867
820
}
@@ -871,24 +824,11 @@ extension type const Int16._(int _) implements FixedInt {
871
824
/// The result r of this operation satisfies: `this == (this ~/ other) *`
872
825
/// `other + r` . As a consequence, the remainder `r` has the same sign as the
873
826
/// dividend `this` .
827
+ @redeclare
874
828
Int16 remainder (Int16 other) {
875
829
return Int16 .fromUnchecked (_.remainder (other._));
876
830
}
877
831
878
- /// This number as a [double] .
879
- ///
880
- /// If an integer number is not precisely representable as a [double] , an
881
- /// approximation is returned.
882
- double toDouble () => _.toDouble ();
883
-
884
- /// This number as an [int] .
885
- ///
886
- /// This is the underlying integer representation of a [Int16] , and is
887
- /// effectively an identity function, but for consistency and completeness,
888
- /// it is provided as a method to discourage casting.
889
- @redeclare
890
- int toInt () => _;
891
-
892
832
/// Returns this integer split into two parts: high and low bits.
893
833
///
894
834
/// The high bits are the most significant bits, and the low bits are the
@@ -901,6 +841,7 @@ extension type const Int16._(int _) implements FixedInt {
901
841
/// The sign of the returned value is always positive.
902
842
///
903
843
/// See [num.operator %] for more details.
844
+ @redeclare
904
845
Int16 operator % (Int16 other) {
905
846
return Int16 .fromUnchecked (_ % other._);
906
847
}
@@ -920,6 +861,7 @@ extension type const Int16._(int _) implements FixedInt {
920
861
/// ```dart
921
862
/// Int16(2) * Int16(3); // 6
922
863
/// ```
864
+ @redeclare
923
865
Int16 operator * (Int16 other) => Int16 (_ * other._);
924
866
925
867
/// Multiplies this number by other.
@@ -990,6 +932,7 @@ extension type const Int16._(int _) implements FixedInt {
990
932
/// ```dart
991
933
/// Int16(2) + Int16(3); // 5
992
934
/// ```
935
+ @redeclare
993
936
Int16 operator + (Int16 other) => Int16 (_ + other._);
994
937
995
938
/// Adds [other] to this number.
@@ -1060,6 +1003,7 @@ extension type const Int16._(int _) implements FixedInt {
1060
1003
/// ```dart
1061
1004
/// Int16(3) - Int16(2); // 1
1062
1005
/// ```
1006
+ @redeclare
1063
1007
Int16 operator - (Int16 other) => Int16 (_ - other._);
1064
1008
1065
1009
/// Subtracts [other] from this number.
@@ -1115,44 +1059,6 @@ extension type const Int16._(int _) implements FixedInt {
1115
1059
/// ```
1116
1060
Int16 clampedSubtract (Int16 other) => Int16 .fromClamped (_ - other._);
1117
1061
1118
- /// Whether this number is numerically smaller than [other] .
1119
- ///
1120
- /// ## Example
1121
- ///
1122
- /// ```dart
1123
- /// Int16(2) < Int16(3); // true
1124
- /// ```
1125
- bool operator < (Int16 other) => _ < other._;
1126
-
1127
- /// Whether this number is numerically smaller than or equal to [other] .
1128
- ///
1129
- /// ## Example
1130
- ///
1131
- /// ```dart
1132
- /// Int16(2) <= Int16(3); // true
1133
- /// Int16(3) <= Int16(3); // true
1134
- /// ```
1135
- bool operator <= (Int16 other) => _ <= other._;
1136
-
1137
- /// Whether this number is numerically greater than [other] .
1138
- ///
1139
- /// ## Example
1140
- ///
1141
- /// ```dart
1142
- /// Int16(3) > Int16(2); // true
1143
- /// ```
1144
- bool operator > (Int16 other) => _ > other._;
1145
-
1146
- /// Whether this number is numerically greater than or equal to [other] .
1147
- ///
1148
- /// ## Example
1149
- ///
1150
- /// ```dart
1151
- /// Int16(3) >= Int16(2); // true
1152
- /// Int16(3) >= Int16(3); // true
1153
- /// ```
1154
- bool operator >= (Int16 other) => _ >= other._;
1155
-
1156
1062
/// The negation of `this` .
1157
1063
///
1158
1064
/// If the result is out of range, it asserts in debug mode, and wraps in
@@ -1168,6 +1074,7 @@ extension type const Int16._(int _) implements FixedInt {
1168
1074
/// ```dart
1169
1075
/// -Int16(3); // -3
1170
1076
/// ```
1077
+ @redeclare
1171
1078
Int16 operator - () => Int16 (- _);
1172
1079
1173
1080
/// The negation of `this` .
@@ -1234,18 +1141,21 @@ extension type const Int16._(int _) implements FixedInt {
1234
1141
/// ```dart
1235
1142
/// Int16(10) ~/ Int16(3); // 3
1236
1143
/// ```
1144
+ @redeclare
1237
1145
Int16 operator ~ / (Int16 other) => Int16 .fromUnchecked (_ ~ / other._);
1238
1146
1239
1147
/// Bit-wise and operator.
1240
1148
///
1241
1149
/// See [int.operator &] for more details.
1150
+ @redeclare
1242
1151
Int16 operator & (Int16 other) {
1243
1152
return _descriptor.uncheckedBinaryAnd (_, other._);
1244
1153
}
1245
1154
1246
1155
/// Bit-wise or operator.
1247
1156
///
1248
1157
/// See [int.operator |] for more details.
1158
+ @redeclare
1249
1159
Int16 operator | (Int16 other) {
1250
1160
return _descriptor.uncheckedBinaryOr (_, other._);
1251
1161
}
@@ -1257,6 +1167,7 @@ extension type const Int16._(int _) implements FixedInt {
1257
1167
/// `pow(2, shiftAmount)` .
1258
1168
///
1259
1169
/// [shiftAmount] must be non-negative.
1170
+ @redeclare
1260
1171
Int16 operator >> (int shiftAmount) {
1261
1172
return _descriptor.uncheckedShiftRight (_, shiftAmount);
1262
1173
}
@@ -1279,6 +1190,7 @@ extension type const Int16._(int _) implements FixedInt {
1279
1190
/// ```dart
1280
1191
/// Int16(3) << 2; // 12
1281
1192
/// ```
1193
+ @redeclare
1282
1194
Int16 operator << (int shiftAmount) {
1283
1195
return Int16 (_descriptor.overflowingShiftLeft (_, shiftAmount));
1284
1196
}
@@ -1379,6 +1291,7 @@ extension type const Int16._(int _) implements FixedInt {
1379
1291
/// range.
1380
1292
/// - [clampedUnsignedShiftRight] , which clamps the result if it is out of
1381
1293
/// range.
1294
+ @redeclare
1382
1295
Int16 operator >>> (int shiftAmount) {
1383
1296
return Int16 (_ >>> shiftAmount);
1384
1297
}
@@ -1457,6 +1370,7 @@ extension type const Int16._(int _) implements FixedInt {
1457
1370
/// Bit-wise exclusive-or operator.
1458
1371
///
1459
1372
/// See [int.operator ^] for more details.
1373
+ @redeclare
1460
1374
Int16 operator ^ (Int16 other) {
1461
1375
return _descriptor.uncheckedBinaryXor (_, other._);
1462
1376
}
@@ -1465,6 +1379,7 @@ extension type const Int16._(int _) implements FixedInt {
1465
1379
///
1466
1380
/// The bitwise compliment of an unsigned integer is its two's complement,
1467
1381
/// or the number inverted.
1382
+ @redeclare
1468
1383
Int16 operator ~ () {
1469
1384
return _descriptor.uncheckedBinaryNot (_);
1470
1385
}
0 commit comments