isSameKindCast

Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type.

Usage

var isSameKindCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' );

isSameKindCast( from, to )

Returns a boolean indicating whether an array data type can be safely cast to, or is of the same "kind" as, another array data type (e.g., casting between signed integers or between floats).

var bool = isSameKindCast( 'float32', 'float64' );
// returns true

bool = isSameKindCast( 'uint16', 'int16' );
// returns false

Examples

var cartesianSquare = require( '@stdlib/array/cartesian-square' );
var dtypes = require( '@stdlib/array/dtypes' );
var isSameKindCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' );

// Generate a list of dtype pairs:
var dt = cartesianSquare( dtypes() );

// For each data type pair, determine whether one can cast from one data type to another...
var i;
for ( i = 0; i < dt.length; i++ ) {
    console.log( '%s. Allowed cast? %s.', dt[i].join( ' => ' ), isSameKindCast.apply( null, dt[i] ) );
}
Did you find this page helpful?