Skip to content

Commit 48dfcc7

Browse files
committed
Add minInt and maxInt.
1 parent 34b1851 commit 48dfcc7

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
1010
[file an issue]: https://github.com/matanlurey/binary.dart/issues
1111

12+
## 4.0.0-alpha+3
13+
14+
**New features**:
15+
16+
- Added `<Int>.maxInt` and `<Int>.minInt` as static (`int`) constants.
17+
1218
## 4.0.0-alpha+2
1319

1420
**Breaking changes**:

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name: binary
44
description: Utilities for accessing binary data and bit manipulation in Dart and Flutter
5-
version: 4.0.0-alpha+2
5+
version: 4.0.0-alpha+3
66

77
environment:
88
# Required for https://github.com/dart-lang/sdk/issues/55135

tool/template

+16-6
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,40 @@ extension type const {{NAME}}._(int _) implements int {
6464
static const _descriptor = IntDescriptor<{{NAME}}>.{{CONSTRUCTOR}}(
6565
{{NAME}}.fromUnchecked,
6666
width: width,
67-
max: {{MAX}},
67+
max: maxInt,
6868
);
6969

70+
/// The minimum value that this type can represent, as a plain [int].
71+
///
72+
/// This is equivalent to `{{NAME}}.min as int`.
73+
static const minInt = {{MIN}};
74+
75+
/// The maximum value that this type can represent, as a plain [int].
76+
///
77+
/// This is equivalent to `{{NAME}}.max as int`.
78+
static const maxInt = {{MAX}};
79+
7080
/// Always `0`.
7181
static const zero = {{NAME}}.fromUnchecked(0);
7282

7383
/// Always `1`.
7484
static const one = {{NAME}}.fromUnchecked(1);
7585

7686
/// The minimum value that this type can represent.
77-
static const min = {{NAME}}.fromUnchecked({{MIN}});
87+
static const min = {{NAME}}.fromUnchecked(minInt);
7888

7989
/// The maximum value that this type can represent.
80-
static const max = {{NAME}}.fromUnchecked({{MAX}});
90+
static const max = {{NAME}}.fromUnchecked(maxInt);
8191

8292
/// The number of bits used to represent values of this type.
8393
static const width = {{WIDTH}};
8494

8595
/// Returns whether [v] is in a valid range for {{NAME}}.
86-
static bool isValid(int v) => v >= {{MIN}} && v <= {{MAX}};
96+
static bool isValid(int v) => v >= minInt && v <= maxInt;
8797

8898
/// Throws a [RangeError] if [value] is not in a valid range for {{NAME}}.
8999
static void checkRange(int value) {
90-
RangeError.checkValueInInterval(value, {{MIN}}, {{MAX}}, 'value');
100+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
91101
}
92102

93103
/// Defines [v] as {{DESCRIPTION}}, wrapping if necessary.
@@ -106,7 +116,7 @@ extension type const {{NAME}}._(int _) implements int {
106116
// Dart2JS crashes if the boolean is first in this expression, but have
107117
// not been able to reproduce it in a minimal example yet, so this is a
108118
// workaround.
109-
v >= {{MIN}} && v <= {{MAX}} || !debugCheckUncheckedInRange ,
119+
v >= minInt && v <= maxInt || !debugCheckUncheckedInRange ,
110120
'Value out of range: $v.\n\n'
111121
'This should never happen, and is likely a bug. To intentionally '
112122
'overflow, even in debug mode, set '

0 commit comments

Comments
 (0)