Skip to content

Commit 5951cbf

Browse files
committed
feat: add assert/is-almost-same-value-complex64array
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 835bec5 commit 5951cbf

File tree

10 files changed

+722
-0
lines changed

10 files changed

+722
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isAlmostSameValueComplex64Array
22+
23+
> Test if two arguments are both [Complex64Arrays][@stdlib/array/complex64] and contain respective elements which are [approximately the same value][@stdlib/assert/is-almost-same-value] within a specified number of ULPs (units in the last place).
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var isAlmostSameValueComplex64Array = require( '@stdlib/assert/is-almost-same-value-complex64array' );
33+
```
34+
35+
#### isAlmostSameValueComplex64Array( v1, v2, maxULP )
36+
37+
Tests if two arguments are both [Complex64Arrays][@stdlib/array/complex64] and contain respective elements which are [approximately the same value][@stdlib/assert/is-almost-same-value] within a specified number of ULPs (units in the last place).
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var EPS = require( '@stdlib/constants/float32/eps' );
43+
var Complex64Array = require( '@stdlib/array/complex64' );
44+
45+
var x = new Complex64Array( [ 1.0, 2.0 ] );
46+
var y = new Complex64Array( [ 1.0+EPS, 2.0 ] );
47+
48+
var bool = isAlmostSameValueComplex64Array( x, y, 0 );
49+
// returns false
50+
51+
bool = isAlmostSameValueComplex64Array( x, y, 1 );
52+
// returns true
53+
54+
bool = isAlmostSameValueComplex64Array( x, [ 1.0, 2.0 ], 1 );
55+
// returns false
56+
```
57+
58+
</section>
59+
60+
<!-- /.usage -->
61+
62+
<section class="notes">
63+
64+
</section>
65+
66+
<!-- /.notes -->
67+
68+
<section class="examples">
69+
70+
## Examples
71+
72+
<!-- eslint no-undef: "error" -->
73+
74+
<!-- eslint-disable id-length -->
75+
76+
```javascript
77+
var Complex64Array = require( '@stdlib/array/complex64' );
78+
var isAlmostSameValueComplex64Array = require( '@stdlib/assert/is-almost-same-value-complex64array' );
79+
80+
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
81+
var y = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
82+
var out = isAlmostSameValueComplex64Array( x, y, 0 );
83+
console.log( out );
84+
// => true
85+
86+
x = new Complex64Array( [ -0.0, 0.0, -0.0, 0.0 ] );
87+
y = new Complex64Array( [ 0.0, -0.0, 0.0, -0.0 ] );
88+
out = isAlmostSameValueComplex64Array( x, y, 0 );
89+
console.log( out );
90+
// => false
91+
92+
x = new Complex64Array( [ NaN, NaN, NaN, NaN ] );
93+
y = new Complex64Array( [ NaN, NaN, NaN, NaN ] );
94+
out = isAlmostSameValueComplex64Array( x, y, 0 );
95+
console.log( out );
96+
// => true
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
104+
105+
<section class="related">
106+
107+
</section>
108+
109+
<!-- /.related -->
110+
111+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
112+
113+
<section class="links">
114+
115+
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
116+
117+
[@stdlib/assert/is-almost-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-almost-same-value
118+
119+
</section>
120+
121+
<!-- /.links -->
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var zeroTo = require( '@stdlib/array/base/zero-to' );
27+
var Complex64Array = require( '@stdlib/array/complex64' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var isAlmostSameValueComplex64Array = require( './../lib' ); // eslint-disable-line id-length
31+
32+
33+
// FUNCTIONS //
34+
35+
/**
36+
* Creates a benchmark function.
37+
*
38+
* @private
39+
* @param {PositiveInteger} len - array length
40+
* @returns {Function} benchmark function
41+
*/
42+
function createBenchmark( len ) {
43+
var x = new Complex64Array( zeroTo( len*2 ) );
44+
var y = new Complex64Array( zeroTo( len*2 ) );
45+
return benchmark;
46+
47+
/**
48+
* Benchmark function.
49+
*
50+
* @private
51+
* @param {Benchmark} b - benchmark instance
52+
*/
53+
function benchmark( b ) {
54+
var bool;
55+
var i;
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
bool = isAlmostSameValueComplex64Array( x, y, 1 );
60+
if ( typeof bool !== 'boolean' ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isBoolean( bool ) ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
}
71+
}
72+
73+
74+
// MAIN //
75+
76+
/**
77+
* Main execution sequence.
78+
*
79+
* @private
80+
*/
81+
function main() {
82+
var len;
83+
var min;
84+
var max;
85+
var f;
86+
var i;
87+
88+
min = 1; // 10^min
89+
max = 6; // 10^max
90+
91+
for ( i = min; i <= max; i++ ) {
92+
len = pow( 10, i );
93+
f = createBenchmark( len );
94+
bench( format( '%s:len=%d', pkg, len ), f );
95+
}
96+
}
97+
98+
main();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
{{alias}}( v1, v2, maxULP )
3+
Tests if two arguments are both Complex64Arrays and contain respective
4+
elements which are approximately the same value within a specified number of
5+
ULPs (units in the last place).
6+
7+
The function differs from the `===` operator in that the function treats
8+
`-0` and `+0` as distinct and `NaNs` as the same.
9+
10+
Parameters
11+
----------
12+
v1: any
13+
First input value.
14+
15+
v2: any
16+
Second input value.
17+
18+
maxULP: integer
19+
Maximum allowed ULP difference.
20+
21+
Returns
22+
-------
23+
bool: boolean
24+
Boolean indicating whether two arguments are approximately the same
25+
value.
26+
27+
Examples
28+
--------
29+
> var x = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
30+
> var y = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
31+
> var bool = {{alias}}( x, y, 0 )
32+
true
33+
34+
> x = new {{alias:@stdlib/array/complex64}}( [ NaN, NaN, NaN, NaN ] );
35+
> y = new {{alias:@stdlib/array/complex64}}( [ NaN, NaN, NaN, NaN ] );
36+
> bool = {{alias}}( x, y, 1 )
37+
true
38+
39+
See Also
40+
--------
41+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Tests if two arguments are both Complex64Arrays and contain respective elements which are approximately the same value within a specified number of ULPs (units in the last place).
23+
*
24+
* ## Notes
25+
*
26+
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same.
27+
*
28+
* @param v1 - first input value
29+
* @param v2 - second input value
30+
* @param maxULP - maximum allowed ULP difference
31+
* @returns boolean indicating whether two arguments are approximately the same value
32+
*
33+
* @example
34+
* var Complex64Array = require( '@stdlib/array/complex64' );
35+
*
36+
* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
37+
* var y = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
38+
*
39+
* var out = isAlmostSameValueComplex64Array( x, y, 0 );
40+
* // returns true
41+
*
42+
* @example
43+
* var Complex64Array = require( '@stdlib/array/complex64' );
44+
*
45+
* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
46+
* var y = new Complex64Array( [ 1.0, 2.0, 4.0, 4.0 ] );
47+
*
48+
* var out = isAlmostSameValueComplex64Array( x, y, 1 );
49+
* // returns false
50+
*/
51+
declare function isAlmostSameValueComplex64Array( v1: any, v2: any, maxULP: number ): boolean;
52+
53+
54+
// EXPORTS //
55+
56+
export = isAlmostSameValueComplex64Array;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import isAlmostSameValueComplex64Array = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isAlmostSameValueComplex64Array( 3.14, 3.14, 1 ); // $ExpectType boolean
27+
isAlmostSameValueComplex64Array( null, null, 1 ); // $ExpectType boolean
28+
isAlmostSameValueComplex64Array( 'beep', 'boop', 1 ); // $ExpectType boolean
29+
}
30+
31+
// The compiler throws an error if the function is provided a third argument which is not a number...
32+
{
33+
isAlmostSameValueComplex64Array( 3.14, 3.14, '1' ); // $ExpectError
34+
isAlmostSameValueComplex64Array( 3.14, 3.14, true ); // $ExpectError
35+
isAlmostSameValueComplex64Array( 3.14, 3.14, false ); // $ExpectError
36+
isAlmostSameValueComplex64Array( 3.14, 3.14, null ); // $ExpectError
37+
isAlmostSameValueComplex64Array( 3.14, 3.14, undefined ); // $ExpectError
38+
isAlmostSameValueComplex64Array( 3.14, 3.14, [] ); // $ExpectError
39+
isAlmostSameValueComplex64Array( 3.14, 3.14, {} ); // $ExpectError
40+
isAlmostSameValueComplex64Array( 3.14, 3.14, ( x: number ): number => x ); // $ExpectError
41+
}
42+
43+
// The compiler throws an error if the function is provided an unsupported number of arguments...
44+
{
45+
isAlmostSameValueComplex64Array(); // $ExpectError
46+
isAlmostSameValueComplex64Array( 3.14 ); // $ExpectError
47+
isAlmostSameValueComplex64Array( 3.14, 3.14 ); // $ExpectError
48+
isAlmostSameValueComplex64Array( 'beep', 'beep', 2, {} ); // $ExpectError
49+
}

0 commit comments

Comments
 (0)