@stdlib/array-base-assert-is-mostly-safe-data-type-cast
v0.2.2
Published
Determine if an array data type can be safely cast or, for floating-point data types, downcast to another array data type.
Downloads
294
Readme
isMostlySafeCast
Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type.
Installation
npm install @stdlib/array-base-assert-is-mostly-safe-data-type-cast
Usage
var isMostlySafeCast = require( '@stdlib/array-base-assert-is-mostly-safe-data-type-cast' );
isMostlySafeCast( from, to )
Returns a boolean
indicating whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type.
var bool = isMostlySafeCast( 'float32', 'float64' );
// returns true
bool = isMostlySafeCast( 'float64', 'int32' );
// returns false
Examples
var cartesianSquare = require( '@stdlib/array-base-cartesian-square' );
var dtypes = require( '@stdlib/array-dtypes' );
var isMostlySafeCast = require( '@stdlib/array-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] ) );
}
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.