isMostlySafeCast
Determine whether an ndarray data type can be safely cast or, for floating-point data types, downcast to another ndarray data type.
Usage
var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' );
isMostlySafeCast( from, to )
Returns a boolean
indicating whether an ndarray data type can be safely cast or, for floating-point data types, downcast to another ndarray data type.
var bool = isMostlySafeCast( 'float32', 'float64' );
// returns true
bool = isMostlySafeCast( 'float64', 'int32' );
// returns false
Examples
var cartesianSquare = require( '@stdlib/array/cartesian-square' );
var dtypes = require( '@stdlib/ndarray/dtypes' );
var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' );
// Generate a list of dtype pairs:
var dt = cartesianSquare( dtypes() );
// For each data type pair, determine whether one can cast to another data type...
var i;
for ( i = 0; i < dt.length; i++ ) {
console.log( '%s. Can cast? %s.', dt[i].join( ' => ' ), isMostlySafeCast.apply( null, dt[i] ) );
}