dart

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


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 ?


Solution

  • 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 in native code, but it doesn't look like there are constants yet. If ever. The values are:

    const int maxInteger =  0x7FFFFFFFFFFFFFFF;
    const int minInteger = -0x8000000000000000;
    

    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.

    The maximal finite web integer is therefore also double.maxFinite, and the maximal web integer is double.infinity. Minimum values are just the negative of those.

    The maximal precise integer would be 2^54 (the first integer that cannot be represented as a double is that plus one).

    const int maxPreciseWebInt = 0x20000000000000;