Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jan 18, 2024
1 parent 60427ff commit 77e6e18
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions is-same-complex128/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# isSameComplex128

> Test if two arguments are both [double-precision complex floating-point numbers][@stdlib/complex/float64] and have the [same value][@stdlib/assert/is-same-value].
<section class="usage">

## Usage

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

#### isSameComplex128( v1, v2 )

Tests if two arguments are both [double-precision complex floating-point numbers][@stdlib/complex/float64] and have the [same value][@stdlib/assert/is-same-value].

```javascript
var Complex128 = require( '@stdlib/complex/float64' );

var x = new Complex128( 1.0, 2.0 );
var y = new Complex128( 1.0, 2.0 );
var bool = isSameComplex128( x, y );
// returns true
```

</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 Complex128 = require( '@stdlib/complex/float64' );
var isSameComplex128 = require( '@stdlib/assert/is-same-complex128' );

var x = new Complex128( 1.0, 2.0 );
var y = new Complex128( 1.0, 2.0 );
var out = isSameComplex128( x, y );
// returns true

x = new Complex128( 0.0, -0.0 );
y = new Complex128( -0.0, 0.0 );
out = isSameComplex128( x, y );
// returns false

x = new Complex128( NaN, NaN );
y = new Complex128( NaN, NaN );
out = isSameComplex128( 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/complex/float64]: https://github.com/stdlib-js/complex-float64

[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/assert/tree/main/is-same-value

</section>

<!-- /.links -->
98 changes: 98 additions & 0 deletions is-same-complex128/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 Complex128 = require( '@stdlib/complex/float64' );
var isBoolean = require( './../../is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isSameComplex128 = require( './../lib' );


// MAIN //

bench( pkg+'::true', function benchmark( b ) {
var values;
var bool;
var v;
var i;

values = [
new Complex128( 5.0, 3.0 ),
new Complex128( NaN, NaN ),
new Complex128( 0.0, -0.0 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = values[ i%values.length ];
bool = isSameComplex128( v, v );
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();
});

bench( pkg+'::false', function benchmark( b ) {
var values1;
var values2;
var bool;
var v1;
var v2;
var i;

values1 = [
new Complex128( 5.0, 3.0 ),
new Complex128( NaN, NaN ),
new Complex128( 0.0, -0.0 ),
3.0,
NaN
];
values2 = [
new Complex128( 5.0, -3.0 ),
new Complex128( NaN, 2.0 ),
new Complex128( 0.0, 10.0 ),
-3.0,
5.0
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v1 = values1[ i%values1.length ];
v2 = values2[ i%values2.length ];
bool = isSameComplex128( v1, v2 );
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();
});
36 changes: 36 additions & 0 deletions is-same-complex128/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

{{alias}}( v1, v2 )
Tests if two arguments are both double-precision complex floating-point
numbers and have the same value.

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/complex/float64}}( 1.0, 2.0 );
> var y = new {{alias:@stdlib/complex/float64}}( 1.0, 2.0 );
> var bool = {{alias}}( x, y )
true

> x = new {{alias:@stdlib/complex/float64}}( NaN, NaN );
> y = new {{alias:@stdlib/complex/float64}}( NaN, NaN );
> bool = {{alias}}( x, y )
true

See Also
--------

55 changes: 55 additions & 0 deletions is-same-complex128/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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 double-precision complex floating-point numbers and have the same value.
*
* ## 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 Complex128 = require( '@stdlib/complex/float64' );
*
* var x = new Complex128( 1.0, 2.0 );
* var y = new Complex128( 1.0, 2.0 );
*
* var out = isSameComplex128( x, y );
* // returns true
*
* @example
* var Complex128 = require( '@stdlib/complex/float64' );
*
* var x = new Complex128( 1.0, 2.0 );
* var y = new Complex128( -1.0, -2.0 );
*
* var out = isSameComplex128( x, y );
* // returns false
*/
declare function isSameComplex128( v1: any, v2: any ): boolean;


// EXPORTS //

export = isSameComplex128;
36 changes: 36 additions & 0 deletions is-same-complex128/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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 isSameComplex128 = require( './index' );


// TESTS //

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

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isSameComplex128(); // $ExpectError
isSameComplex128( 3.14 ); // $ExpectError
isSameComplex128( 'beep', 'beep', 3.14 ); // $ExpectError
}
40 changes: 40 additions & 0 deletions is-same-complex128/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 Complex128 = require( '@stdlib/complex/float64' );
var isSameComplex128 = require( './../lib' );

var x = new Complex128( 1.0, 2.0 );
var y = new Complex128( 1.0, 2.0 );
var out = isSameComplex128( x, y );
console.log( out );
// => true

x = new Complex128( 0.0, -0.0 );
y = new Complex128( -0.0, 0.0 );
out = isSameComplex128( x, y );
console.log( out );
// => false

x = new Complex128( NaN, NaN );
y = new Complex128( NaN, NaN );
out = isSameComplex128( x, y );
console.log( out );
// => true
Loading

0 comments on commit 77e6e18

Please sign in to comment.