About stdlib...
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!
Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant.
To use in Observable,
cscal = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-cscal@umd/browser.js' )To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:
var cscal = require( 'path/to/vendor/umd/blas-base-cscal/index.js' )To include the bundle in a webpage,
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-cscal@umd/browser.js"></script>If no recognized module system is present, access bundle contents via the global scope:
<script type="text/javascript">
(function () {
window.cscal;
})();
</script>Scales values from x by alpha.
var Complex64Array = require( '@stdlib/array-complex64' );
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var x = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
var alpha = new Complex64( 2.0, 0.0 );
cscal( 3, alpha, x, 1 );
// x => <Complex64Array>[ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ]The function has the following parameters:
- N: number of indexed elements.
- alpha: scalar
Complex64constant. - x: input
Complex64Array. - strideX: index increment for
x.
The N and stride parameters determine how values from x are scaled by alpha. For example, to scale every other value in x by alpha,
var Complex64Array = require( '@stdlib/array-complex64' );
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var alpha = new Complex64( 2.0, 0.0 );
cscal( 2, alpha, x, 2 );
// x => <Complex64Array>[ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ]Note that indexing is relative to the first index. To introduce an offset, use typed array views.
var Complex64Array = require( '@stdlib/array-complex64' );
var Complex64 = require( '@stdlib/complex-float32-ctor' );
// Initial array:
var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
// Define a scalar constant:
var alpha = new Complex64( 2.0, 2.0 );
// Create an offset view:
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
// Scales every other value from `x1` by `alpha`...
cscal( 3, alpha, x1, 1 );
// x0 => <Complex64Array>[ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0, -2.0, 30.0 ]Scales values from x by alpha using alternative indexing semantics.
var Complex64Array = require( '@stdlib/array-complex64' );
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var alpha = new Complex64( 2.0, 2.0 );
cscal.ndarray( 3, alpha, x, 1, 0 );
// x => <Complex64Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]The function has the following additional parameters:
- offsetX: starting index for
x.
While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to scale every other value in the input strided array starting from the second element,
var Complex64Array = require( '@stdlib/array-complex64' );
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var alpha = new Complex64( 2.0, 2.0 );
cscal.ndarray( 2, alpha, x, 2, 1 );
// x => <Complex64Array>[ 1.0, 2.0, -2.0, 14.0, 5.0, 6.0, -2.0, 30.0 ]<!DOCTYPE html>
<html lang="en">
<body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@umd/browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/array-filled-by@umd/browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32-ctor@umd/browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-cscal@umd/browser.js"></script>
<script type="text/javascript">
(function () {
function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}
var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.toString() );
var alpha = new Complex64( 2.0, 2.0 );
console.log( alpha.toString() );
// Scale elements from `x` by `alpha`:
cscal( x.length, alpha, x, 1 );
console.log( x.get( x.length-1 ).toString() );
})();
</script>
</body>
</html>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.
See LICENSE.
Copyright © 2016-2025. The Stdlib Authors.