kotlinfloating-pointdoubleprimitive-types

Min and Max values of Float and Double types in Kotlin


It's simple to find out what the exact min and max values for Int and Long integers are in Kotlin:

Signed 32 bit Integer:

Int.MIN_VALUE       // -2147483648
Int.MAX_VALUE       //  2147483647

Signed 64 bit Integer:

Long.MIN_VALUE      // -9223372036854775808
Long.MAX_VALUE      //  9223372036854775807

However, if I try to print Float or Double types' ranges of min and max values, I'll get unbalanced numbers (where both values will be expressed using a scientific notation).

Signed 32 bit Floating Point Number:

Float.MIN_VALUE     //  1.4e-45
Float.MAX_VALUE     //  3.4028235e38

Signed 64 bit Floating Point Number:

Double.MIN_VALUE    //  4.9e-324
Double.MAX_VALUE    //  1.7976931348623157e308

Why the positive and negative values of Float and Double types are so "unbalanced"?


P. S.

In C# language, min and max absolute values of Double are identical (or "balanced").

public const double MaxValue = 1.7976931348623157E+308;

public const double MinValue = -1.7976931348623157E+308;

Solution

  • The conceptual definition of MIN_VALUE is different for integers vs floating-point numbers.

    In other words, 1.4E-45 is 0.00[40 zeroes]0014, and not a very large negative number. The largest possible negative value is represented by -1 * Float.MAX_VALUE.