We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
isMostlySafeCast
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
Determine whether an ndarray [data type][@stdlib/ndarray/dtypes] can be safely cast or, for floating-point data types, downcast to another ndarray [data type][@stdlib/ndarray/dtypes].
bash
npm install @stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast
javascript
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][@stdlib/ndarray/dtypes] can be safely cast or, for floating-point data types, downcast to another ndarray [data type][@stdlib/ndarray/dtypes].
javascript
var bool = isMostlySafeCast( 'float32', 'float64' );
// returns true
bool = isMostlySafeCast( 'float64', 'int32' );
// returns false
javascript
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] ) );
}