Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions lib/node_modules/@stdlib/number/int16/base/mul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# mul

> Perform C-like multiplication of two signed 16-bit integers.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var mul = require( '@stdlib/number/int16/base/mul' );
```

#### mul( a, b )

Performs C-like multiplication of two signed 16-bit integers.

```javascript
var v = mul( -10|0, 4|0 );
// returns -40
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- The function emulates C-like multiplication of two signed 16-bit integers.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var INT16_MIN = require( '@stdlib/constants/int16/min' );
var INT16_MAX = require( '@stdlib/constants/int16/max' );
var mul = require( '@stdlib/number/int16/base/mul' );

var x = discreteUniform( 100, INT16_MIN, INT16_MAX );
var y = discreteUniform( 100, INT16_MIN, INT16_MAX );

logEachMap( '%d x %d = %d', x, y, mul );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var minstd = require( '@stdlib/random/base/minstd' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var mul = require( './../lib' );
var polyfill = require( './../lib/polyfill.js' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = mul( x|0, x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::polyfill', pkg ), function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = polyfill( x|0, x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::naive_multiplication', pkg ), function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = ( x|0 ) * ( x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/number/int16/base/mul/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{{alias}}( a, b )
Performs C-like multiplication of two signed 16-bit integers.

Parameters
----------
a: integer
Signed 16-bit integer.

b: integer
Signed 16-bit integer.

Returns
-------
out: integer
Product.

Examples
--------
> var v = {{alias}}( -10|0, 4|0 )
-40

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Performs C-like multiplication of two signed 16-bit integers.
*
* @param a - signed 16-bit integer
* @param b - signed 16-bit integer
* @returns product
*
* @example
* var v = mul( -10|0, 4|0 );
* // returns -40
*/
declare function mul( a: number, b: number ): number;


// EXPORTS //

export = mul;
55 changes: 55 additions & 0 deletions lib/node_modules/@stdlib/number/int16/base/mul/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import mul = require( './index' );


// TESTS //

// The function returns a number...
{
mul( -10, 4 ); // $ExpectType number
}

// The compiler throws an error if the function is provided values other than two numbers...
{
mul( true, 3 ); // $ExpectError
mul( false, 2 ); // $ExpectError
mul( '5', 1 ); // $ExpectError
mul( [], 1 ); // $ExpectError
mul( {}, 2 ); // $ExpectError
mul( ( x: number ): number => x, 2 ); // $ExpectError

mul( 9, true ); // $ExpectError
mul( 9, false ); // $ExpectError
mul( 5, '5' ); // $ExpectError
mul( 8, [] ); // $ExpectError
mul( 9, {} ); // $ExpectError
mul( 8, ( x: number ): number => x ); // $ExpectError
mul( [], true ); // $ExpectError
mul( {}, false ); // $ExpectError
mul( false, '5' ); // $ExpectError
mul( {}, [] ); // $ExpectError
mul( '5', ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided insufficient arguments...
{
mul(); // $ExpectError
mul( 3 ); // $ExpectError
}
30 changes: 30 additions & 0 deletions lib/node_modules/@stdlib/number/int16/base/mul/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var INT16_MIN = require( '@stdlib/constants/int16/min' );
var INT16_MAX = require( '@stdlib/constants/int16/max' );
var mul = require( './../lib' );

var x = discreteUniform( 100, INT16_MIN, INT16_MAX );
var y = discreteUniform( 100, INT16_MIN, INT16_MAX );

logEachMap( '%d x %d = %d', x, y, mul );
45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/number/int16/base/mul/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Perform C-like multiplication of two signed 16-bit integers.
*
* @module @stdlib/number/int16/base/mul
*
* @example
* var mul = require( '@stdlib/number/int16/base/mul' );
*
* var v = mul( -10|0, 4|0 );
* // returns -40
*/

// MODULES //

var polyfill = require( './polyfill.js' );


// MAIN //

var main = polyfill;


// EXPORTS //

module.exports = main;
Loading