FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add `assert/is-same-float16array` by Erennn7 · Pull Request #14743 · stdlib-js/stdlib · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (5) .json  (1) .md  (1) .ts  (2) .txt  (1) All 5 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
    • README.md
      • repl.txt
        • index.d.ts
        • test.ts
      • index.js
      • index.js
      • main.js
    • package.json
      • test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!--

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

-->

# isSameFloat16Array

> Test if two arguments are both [Float16Arrays][@stdlib/array/float16] and have the [same values][@stdlib/assert/is-same-value].

<section class="usage">

## Usage

```javascript
var isSameFloat16Array = require( '@stdlib/assert/is-same-float16array' );
```

#### isSameFloat16Array( v1, v2 )

Tests if two arguments are both [Float16Arrays][@stdlib/array/float16] and have the [same values][@stdlib/assert/is-same-value].

```javascript
var Float16Array = require( '@stdlib/array/float16' );

var x = new Float16Array( [ 1.0, 2.0 ] );
var y = new Float16Array( [ 1.0, 2.0 ] );
var bool = isSameFloat16Array( x, y );
// returns true

bool = isSameFloat16Array( x, [ 1.0, 2.0 ] );
// returns false
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the [same value][@stdlib/assert/is-same-value].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var Float16Array = require( '@stdlib/array/float16' );
var isSameFloat16Array = require( '@stdlib/assert/is-same-float16array' );

var x = new Float16Array( [ 1.0, 2.0, 3.0 ] );
var y = new Float16Array( [ 1.0, 2.0, 3.0 ] );
var out = isSameFloat16Array( x, y );
// returns true

x = new Float16Array( [ -0.0, 0.0, -0.0 ] );
y = new Float16Array( [ 0.0, -0.0, 0.0 ] );
out = isSameFloat16Array( x, y );
// returns false

x = new Float16Array( [ NaN, NaN, NaN ] );
y = new Float16Array( [ NaN, NaN, NaN ] );
out = isSameFloat16Array( x, y );
// returns true
```

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

[@stdlib/array/float16]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float16

[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value

</section>

<!-- /.links -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
var zeroTo = require( '@stdlib/array/base/zero-to' );
var Float16Array = require( '@stdlib/array/float16' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var isSameFloat16Array = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = new Float16Array( zeroTo( len ) );
var y = new Float16Array( zeroTo( len ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var bool;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isSameFloat16Array( x, y );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:len=%d', pkg, len ), f );
}
}

main();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

{{alias}}( v1, v2 )
Tests if two arguments are both Float16Arrays and have the same values.

The function differs from the `===` operator in that the function treats
`-0` and `+0` as distinct and `NaNs` as the same.

Parameters
----------
v1: any
First input value.

v2: any
Second input value.

Returns
-------
bool: boolean
Boolean indicating whether two arguments are the same.

Examples
--------
> var x = new {{alias:@stdlib/array/float16}}( [ 1.0, 2.0, 3.0 ] );
> var y = new {{alias:@stdlib/array/float16}}( [ 1.0, 2.0, 3.0 ] );
> var bool = {{alias}}( x, y )
true

> x = new {{alias:@stdlib/array/float16}}( [ NaN, NaN, NaN ] );
> y = new {{alias:@stdlib/array/float16}}( [ NaN, NaN, NaN ] );
> bool = {{alias}}( x, y )
true

See Also
--------

Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
*/

// TypeScript Version: 4.1

/**
* Tests if two arguments are both Float16Arrays and have the same values.
*
* ## Notes
*
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same.
*
* @param v1 - first input value
* @param v2 - second input value
* @returns boolean indicating whether two arguments are the same
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
*
* var x = new Float16Array( [ 1.0, 2.0, 3.0 ] );
* var y = new Float16Array( [ 1.0, 2.0, 3.0 ] );
*
* var out = isSameFloat16Array( x, y );
* // returns true
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
*
* var x = new Float16Array( [ 1.0, 2.0, 3.0 ] );
* var y = new Float16Array( [ 1.0, 2.0, 4.0 ] );
*
* var out = isSameFloat16Array( x, y );
* // returns false
*/
declare function isSameFloat16Array( v1: any, v2: any ): boolean;

Check warning on line 50 in lib/node_modules/@stdlib/assert/is-same-float16array/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

Check warning on line 50 in lib/node_modules/@stdlib/assert/is-same-float16array/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = isSameFloat16Array;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* @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 isSameFloat16Array = require( './index' );


// TESTS //

// The function returns a boolean...
{
isSameFloat16Array( 3.14, 3.14 ); // $ExpectType boolean
isSameFloat16Array( null, null ); // $ExpectType boolean
isSameFloat16Array( 'beep', 'boop' ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isSameFloat16Array(); // $ExpectError
isSameFloat16Array( 3.14 ); // $ExpectError
isSameFloat16Array( 'beep', 'beep', 3.14 ); // $ExpectError
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @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 Float16Array = require( '@stdlib/array/float16' );
var isSameFloat16Array = require( './../lib' );

var x = new Float16Array( [ 1.0, 2.0, 3.0 ] );
var y = new Float16Array( [ 1.0, 2.0, 3.0 ] );
var out = isSameFloat16Array( x, y );
console.log( out );
// => true

x = new Float16Array( [ -0.0, 0.0, -0.0 ] );
y = new Float16Array( [ 0.0, -0.0, 0.0 ] );
out = isSameFloat16Array( x, y );
console.log( out );
// => false

x = new Float16Array( [ NaN, NaN, NaN ] );
y = new Float16Array( [ NaN, NaN, NaN ] );
out = isSameFloat16Array( x, y );
console.log( out );
// => true
Loading

Back | FazBrowse Home | New Git URL