Skip to content

Commit 6e539e7

Browse files
committed
feat: add complex/base/assert namespace
--- 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: na - 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: na - 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 0b5ef42 commit 6e539e7

File tree

7 files changed

+386
-0
lines changed

7 files changed

+386
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
# Assert
22+
23+
> Base (i.e., lower-level) complex number assertion functions.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var assert = require( '@stdlib/complex/base/assert' );
31+
```
32+
33+
#### assert
34+
35+
Namespace containing base (i.e., lower-level) complex number assertion functions.
36+
37+
```javascript
38+
var ns = assert;
39+
// returns {...}
40+
```
41+
42+
The namespace contains the following functions:
43+
44+
<!-- <toc pattern="*"> -->
45+
46+
<div class="namespace-toc">
47+
48+
- <span class="signature">[`isAlmostEqual( z1, z2, maxULP )`][@stdlib/complex/base/assert/is-almost-equal]</span><span class="delimiter">: </span><span class="description">test whether two complex numbers are approximately equal within a specified number of ULPs (units in the last place).</span>
49+
50+
</div>
51+
52+
<!-- </toc> -->
53+
54+
</section>
55+
56+
<!-- /.usage -->
57+
58+
<!-- Package notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
59+
60+
<section class="notes">
61+
62+
</section>
63+
64+
<!-- /.notes -->
65+
66+
<section class="examples">
67+
68+
## Examples
69+
70+
<!-- TODO: better examples -->
71+
72+
<!-- eslint no-undef: "error" -->
73+
74+
```javascript
75+
var objectKeys = require( '@stdlib/utils/keys' );
76+
var ns = require( '@stdlib/complex/base/assert' );
77+
78+
console.log( objectKeys( ns ) );
79+
```
80+
81+
</section>
82+
83+
<!-- /.examples -->
84+
85+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
86+
87+
<section class="related">
88+
89+
</section>
90+
91+
<!-- /.related -->
92+
93+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
94+
95+
<section class="links">
96+
97+
<!-- <toc-links> -->
98+
99+
[@stdlib/complex/base/assert/is-almost-equal]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/base/assert/is-almost-equal
100+
101+
<!-- </toc-links> -->
102+
103+
</section>
104+
105+
<!-- /.links -->
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
/* eslint-disable max-lines */
22+
23+
import isAlmostEqual = require( '@stdlib/complex/base/assert/is-almost-equal' );
24+
25+
/**
26+
* Interface describing the `assert` namespace.
27+
*/
28+
interface Namespace {
29+
/**
30+
* Tests whether two complex numbers are approximately equal within a specified number of ULPs (units in the last place).
31+
*
32+
* ## Notes
33+
*
34+
* - The function returns `false` if either input value has a `NaN` real or imaginary component.
35+
* - The function does not distinguish between `-0` and `+0`, treating them as equal.
36+
*
37+
* @param z1 - first complex number
38+
* @param z2 - second complex number
39+
* @param maxULP - maximum allowed ULP difference
40+
* @returns boolean indicating whether two complex numbers are approximately equal within a specified number of ULPs
41+
*
42+
* @example
43+
* var EPS = require( '@stdlib/constants/float32/eps' );
44+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
45+
*
46+
* var z1 = new Complex64( 1.0, 3.0 );
47+
* var z2 = new Complex64( 1.0+EPS, 3.0 );
48+
*
49+
* var bool = ns.isAlmostEqual( z1, z2, 0 );
50+
* // returns false
51+
*
52+
* bool = ns.isAlmostEqual( z1, z2, 1 );
53+
* // returns true
54+
*/
55+
isAlmostEqual: typeof isAlmostEqual;
56+
}
57+
58+
/**
59+
* Base (i.e., lower-level) complex number assertion functions.
60+
*/
61+
declare var ns: Namespace;
62+
63+
64+
// EXPORTS //
65+
66+
export = ns;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
/* eslint-disable @typescript-eslint/no-unused-expressions */
20+
21+
import ns = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported value is the expected interface...
27+
{
28+
ns; // $ExpectType Namespace
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
var objectKeys = require( '@stdlib/utils/keys' );
22+
var ns = require( './../lib' );
23+
24+
console.log( objectKeys( ns ) );
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
/*
22+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
23+
*/
24+
25+
// MODULES //
26+
27+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Top-level namespace.
34+
*
35+
* @namespace ns
36+
*/
37+
var ns = {};
38+
39+
/**
40+
* @name isAlmostEqual
41+
* @memberof ns
42+
* @readonly
43+
* @type {Function}
44+
* @see {@link module:@stdlib/complex/base/assert/is-almost-equal}
45+
*/
46+
setReadOnly( ns, 'isAlmostEqual', require( '@stdlib/complex/base/assert/is-almost-equal' ) );
47+
48+
/**
49+
* @name isAlmostSameValue
50+
* @memberof ns
51+
* @readonly
52+
* @type {Function}
53+
* @see {@link module:@stdlib/complex/base/assert/is-almost-same-value}
54+
*/
55+
setReadOnly( ns, 'isAlmostSameValue', require( '@stdlib/complex/base/assert/is-almost-same-value' ) );
56+
57+
58+
// EXPORTS //
59+
60+
module.exports = ns;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "@stdlib/complex/base/assert",
3+
"version": "0.0.0",
4+
"description": "Base (i.e., lower-level) complex number assertion functions.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "lib/index.js",
17+
"directories": {
18+
"doc": "./docs",
19+
"example": "./examples",
20+
"lib": "./lib",
21+
"test": "./test"
22+
},
23+
"types": "./docs/types",
24+
"scripts": {},
25+
"homepage": "https://github.com/stdlib-js/stdlib",
26+
"repository": {
27+
"type": "git",
28+
"url": "git://github.com/stdlib-js/stdlib.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/stdlib-js/stdlib/issues"
32+
},
33+
"dependencies": {},
34+
"devDependencies": {},
35+
"engines": {
36+
"node": ">=0.10.0",
37+
"npm": ">2.7.0"
38+
},
39+
"os": [
40+
"aix",
41+
"darwin",
42+
"freebsd",
43+
"linux",
44+
"macos",
45+
"openbsd",
46+
"sunos",
47+
"win32",
48+
"windows"
49+
],
50+
"keywords": [
51+
"stdlib",
52+
"stdtypes",
53+
"types",
54+
"complex",
55+
"cmplx",
56+
"number",
57+
"namespace",
58+
"ns",
59+
"base",
60+
"assert"
61+
]
62+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 tape = require( 'tape' );
24+
var objectKeys = require( '@stdlib/utils/keys' );
25+
var ns = require( './../lib' );
26+
27+
28+
// TESTS //
29+
30+
tape( 'main export is an object', function test( t ) {
31+
t.ok( true, __filename );
32+
t.strictEqual( typeof ns, 'object', 'main export is an object' );
33+
t.end();
34+
});
35+
36+
tape( 'the exported object contains key-value pairs', function test( t ) {
37+
var keys = objectKeys( ns );
38+
t.strictEqual( keys.length > 0, true, 'has keys' );
39+
t.end();
40+
});

0 commit comments

Comments
 (0)