Skip to content
Merged
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
115 changes: 115 additions & 0 deletions lib/node_modules/@stdlib/number/float16/base/sub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!--

@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.

-->

# sub

> Subtract two half-precision floating-point numbers.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var sub = require( '@stdlib/number/float16/base/sub' );
```

#### sub( x, y )

Subtracts two half-precision floating-point numbers.

```javascript
var v = sub( -1.0, 5.0 );
// returns -6.0

v = sub( 2.0, 5.0 );
// returns -3.0

v = sub( 0.0, 5.0 );
// returns -5.0

v = sub( -0.0, 0.0 );
// returns -0.0

v = sub( NaN, NaN );
// returns NaN
```

</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">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

```javascript
var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var uniform = require( '@stdlib/random/array/uniform' );
var map = require( '@stdlib/array/base/map' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var sub = require( '@stdlib/number/float16/base/sub' );

var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 );

logEachMap( 'x: %f, y: %f => %f', x, y, sub );
```

</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,57 @@
/**
* @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 uniform = require( '@stdlib/random/array/uniform' );
var map = require( '@stdlib/array/base/map' );
var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var naryFunction = require( '@stdlib/utils/nary-function' );
var pkg = require( './../package.json' ).name;
var sub = require( './../lib' );


// MAIN //

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

x = map( uniform( 100, -100, 100 ), naryFunction( toFloat16, 1 ) );
y = map( uniform( 100, -100, 100 ), naryFunction( toFloat16, 1 ) );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = sub( x[ i%x.length ], y[ i%y.length ]);
if ( isnan( out ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/number/float16/base/sub/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

{{alias}}( x, y )
Subtracts two half-precision floating-point numbers `x` and `y`.

Parameters
----------
x: number
First input value.

y: number
Second input value.

Returns
-------
z: number
Result.

Examples
--------
> var v = {{alias}}( -1.0, 5.0 )
-6.0
> v = {{alias}}( 2.0, 5.0 )
-3.0
> v = {{alias}}( 0.0, 5.0 )
-5.0
> v = {{alias}}( -0.0, 0.0 )
-0.0
> v = {{alias}}( NaN, NaN )
NaN

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* @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

/**
* Subtracts two half-precision floating-point numbers `x` and `y`.
*
* @param x - first input value
* @param y - second input value
* @returns result
*
* @example
* var v = sub( -1.0, 5.0 );
* // returns -6.0
*
* @example
* var v = sub( 2.0, 5.0 );
* // returns -3.0
*
* @example
* var v = sub( 0.0, 5.0 );
* // returns -5.0
*
* @example
* var v = sub( -0.0, 0.0 );
* // returns -0.0
*
* @example
* var v = sub( NaN, NaN );
* // returns NaN
*/
declare function sub( x: number, y: number ): number;


// EXPORTS //

export = sub;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* @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 sub = require( './index' );


// TESTS //

// The function returns a number...
{
sub( 8.0, 8.0 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a first argument which is not a number...
{
sub( true, 5.0 ); // $ExpectError
sub( false, 5.0 ); // $ExpectError
sub( null, 5.0 ); // $ExpectError
sub( undefined, 5.0 ); // $ExpectError
sub( '5', 5.0 ); // $ExpectError
sub( [], 5.0 ); // $ExpectError
sub( {}, 5.0 ); // $ExpectError
sub( ( x: number ): number => x, 5.0 ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a number...
{
sub( 5.0, true ); // $ExpectError
sub( 5.0, false ); // $ExpectError
sub( 5.0, null ); // $ExpectError
sub( 5.0, undefined ); // $ExpectError
sub( 5.0, '5' ); // $ExpectError
sub( 5.0, [] ); // $ExpectError
sub( 5.0, {} ); // $ExpectError
sub( 5.0, ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
sub(); // $ExpectError
sub( 5.0 ); // $ExpectError
sub( 5.0, 5.0, 5.0 ); // $ExpectError
}
30 changes: 30 additions & 0 deletions lib/node_modules/@stdlib/number/float16/base/sub/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 uniform = require( '@stdlib/random/array/uniform' );
var map = require( '@stdlib/array/base/map' );
var toFloat16 = require( '@stdlib/number/float64/base/to-float16' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var sub = require( './../lib' );

var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 );
var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 );

logEachMap( 'x: %f, y: %f => %f', x, y, sub );
Loading