Skip to content

Instantly share code, notes, and snippets.

@jonathanduke
Last active January 18, 2024 20:30
Show Gist options
  • Save jonathanduke/dad879af094b27b24fd6070e1175e791 to your computer and use it in GitHub Desktop.
Save jonathanduke/dad879af094b27b24fd6070e1175e791 to your computer and use it in GitHub Desktop.
Implementation for int.minValue and int.maxValue in Dart
// https://dartpad.dev/?id=dad879af094b27b24fd6070e1175e791
// Pending feature request: https://github.com/dart-lang/sdk/issues/41717
// Note: this requires Dart 2.14 and above (to support the >>> operator)
class IntRange {
// based on: https://stackoverflow.com/a/75928881
static const int maxValue = (-1 >>> 1);
static const int minValue = -1 - maxValue;
}
void main() {
print('int: ${IntRange.minValue} to ${IntRange.maxValue}');
}
// in DartPad (32-bit), this will print "int: -2147483648 to 2147483647"
// on Android (64-bit), this will print "int: -9223372036854775808 to 9223372036854775807"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment