time-to-botec/squiggle/node_modules/@stdlib/ndarray/base/wrap-index
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
include/stdlib/ndarray/base feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
src feat: add the node modules 2022-12-03 12:44:49 +00:00
manifest.json feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

Wrap Index

Wrap an index on the interval [0,max].

Usage

var wrapIndex = require( '@stdlib/ndarray/base/wrap-index' );

wrapIndex( idx, max )

Wrap an index on the interval [0,max].

var idx = wrapIndex( 2, 10 );
// returns 2

idx = wrapIndex( -5, 10 );
// returns 6

idx = wrapIndex( 15, 10 );
// returns 4

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var wrapIndex = require( '@stdlib/ndarray/base/wrap-index' );

var idx;
var out;
var i;

for ( i = 0; i < 100; i++ ) {
    idx = discreteUniform( -20, 20 );
    out = wrapIndex( idx, 9 );
    console.log( '%d => [%d,%d] => %d', idx, 0, 9, out );
}