Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a constant for max/min int/double value in dart?

Tags:

Is there a constant in dart that tells us what is the max/min int/double value ?

Something like double.infinity but instead double.maxValue ?

like image 441
Rémi Rousselet Avatar asked May 19 '18 21:05

Rémi Rousselet


People also ask

What does int mean in Dart?

In Dart, all numbers are part of the common Object type hierarchy, and there are two concrete, user-visible numeric types: int , representing integer values, and double , representing fractional values.

Is int an object in Dart?

Yes, Dart's int type is a "reference type". Dart does not have value types at all, all values are instances of a class, including integers. (At least technically, function values makes their classes very hard to see.) Integers are immutable and pretends to be canonicalized.

How big can ints get?

These represent numbers in the range -2147483648 through 2147483647. (The range may be larger on machines with a larger natural word size, but not smaller.)


2 Answers

For double there are

double.maxFinite (1.7976931348623157e+308)
double.minPositive (5e-324)

In Dart 1 there was no such number for int. The size of integers was limited only by available memory

In Dart 2 int is limited to 64 bit, but it doesn't look like there are constants yet.

For dart2js different rules apply

When compiling to JavaScript, integers are therefore restricted to 53 significant bits because all JavaScript numbers are double-precision floating point values.

like image 81
Günter Zöchbauer Avatar answered Oct 23 '22 07:10

Günter Zöchbauer


I found this from dart_numerics package.

enter image description here

like image 26
Pinkesh Darji Avatar answered Oct 23 '22 07:10

Pinkesh Darji