Number Unification

Edit pageLast modified: 16 June 2025

Unifying numbers means converting them to a common number type without losing information.

This is currently an internal part of the library, but its logic implementation can be encountered in multiple places, such as statistics, and reading JSON.

The following graph shows the hierarchy of number types in Kotlin DataFrame.

The order is top-down from the most complex type to the simplest one.

For each number type in the graph, it holds that a number of that type can be expressed lossless by a number of a more complex type (any of its parents). This is either because the more complex type has a larger range or higher precision (in terms of bits).

Nullability, while not displayed in the graph, is also taken into account. This means that Int? and Float will be unified to Double?.

Nothing is at the bottom of the graph and is the starting point in unification. This can be interpreted as "no type" and can have no instance, while Nothing? can only be null.