cfdm.integer_dtype

cfdm.integer_dtype(n)[source]

Return the smallest data type that can store the given integer.

New in version (cfdm): 1.11.0.0

Parameters
n: integer

The integer for which a data type is required.

Returns
numpy.dtype
numpy.dtype('int32') if n is representable by a 32-bit

integer, otherwise numpy.dtype(int).

Examples

>>> np.iinfo('int32')
iinfo(min=-2147483648, max=2147483647, dtype=int32)
>>> cfdm.integer_dtype(123)
dtype('int32')
>>> cfdm.integer_dtype(-4294967296)
dtype('int64')
>>> cfdm.integer_dtype(np.iinfo('int32').max)
dtype('int32')
>>> cfdm.integer_dtype(np.iinfo('int32').min)
dtype('int32')
>>> cfdm.integer_dtype(np.iinfo('int32').max + 1)
dtype('int64')
>>> cfdm.integer_dtype(np.iinfo('int32').min - 1)
dtype('int64')