Skip to content

Commit 27a5a10

Browse files
committed
feat: add complex/float64/base/neg
Ref: #2261 --- 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 dc9f39f commit 27a5a10

File tree

28 files changed

+2610
-0
lines changed

28 files changed

+2610
-0
lines changed
Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# cneg
22+
23+
> Negate a double-precision complex floating-point number.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var cneg = require( '@stdlib/complex/float64/base/neg' );
41+
```
42+
43+
#### cneg( z )
44+
45+
Negates a double-precision complex floating-point number.
46+
47+
```javascript
48+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
49+
var real = require( '@stdlib/complex/float64/real' );
50+
var imag = require( '@stdlib/complex/float64/imag' );
51+
52+
var z = new Complex128( -4.2, 5.5 );
53+
54+
var out = cneg( z );
55+
// returns <Complex128>
56+
57+
var re = real( out );
58+
// returns 4.2
59+
60+
var im = imag( out );
61+
// returns -5.5
62+
63+
z = new Complex128( 0.0, 0.0 );
64+
65+
out = cneg( z );
66+
// returns <Complex128>
67+
68+
re = real( out );
69+
// returns -0.0
70+
71+
im = imag( out );
72+
// returns -0.0
73+
74+
z = new Complex128( NaN, NaN );
75+
76+
out = cneg( z );
77+
// returns <Complex128>
78+
79+
re = real( out );
80+
// returns NaN
81+
82+
im = imag( out );
83+
// returns NaN
84+
```
85+
86+
</section>
87+
88+
<!-- /.usage -->
89+
90+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
91+
92+
<section class="notes">
93+
94+
</section>
95+
96+
<!-- /.notes -->
97+
98+
<!-- Package usage examples. -->
99+
100+
<section class="examples">
101+
102+
## Examples
103+
104+
<!-- eslint no-undef: "error" -->
105+
106+
```javascript
107+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
108+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
109+
var cneg = require( '@stdlib/complex/float64/base/neg' );
110+
111+
function randomComplex() {
112+
var re = discreteUniform( -50, 50 );
113+
var im = discreteUniform( -50, 50 );
114+
return new Complex128( re, im );
115+
}
116+
117+
var z;
118+
var o;
119+
var i;
120+
121+
for ( i = 0; i < 100; i++ ) {
122+
z = randomComplex();
123+
o = cneg( z );
124+
console.log( 'negate(%s) = %s', z.toString(), o.toString() );
125+
}
126+
```
127+
128+
</section>
129+
130+
<!-- /.examples -->
131+
132+
<!-- C interface documentation. -->
133+
134+
* * *
135+
136+
<section class="c">
137+
138+
## C APIs
139+
140+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
141+
142+
<section class="intro">
143+
144+
</section>
145+
146+
<!-- /.intro -->
147+
148+
<!-- C usage documentation. -->
149+
150+
<section class="usage">
151+
152+
### Usage
153+
154+
```c
155+
#include "stdlib/complex/float64/base/neg.h"
156+
```
157+
158+
#### stdlib_base_complex128_neg( z )
159+
160+
Negates a double-precision complex floating-point number.
161+
162+
```c
163+
#include "stdlib/complex/float64/ctor.h"
164+
#include "stdlib/complex/float64/real.h"
165+
#include "stdlib/complex/float64/imag.h"
166+
167+
stdlib_complex128_t z = stdlib_complex128( 3.0, -2.0 );
168+
169+
stdlib_complex128_t out = stdlib_base_complex128_neg( z );
170+
171+
double re = stdlib_complex128_real( out );
172+
// returns -3.0
173+
174+
double im = stdlib_complex128_imag( out );
175+
// returns 2.0
176+
```
177+
178+
The function accepts the following arguments:
179+
180+
- **z**: `[in] stdlib_complex128_t` input value.
181+
182+
```c
183+
stdlib_complex128_t stdlib_base_complex128_neg( const stdlib_complex128_t z );
184+
```
185+
186+
</section>
187+
188+
<!-- /.usage -->
189+
190+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
191+
192+
<section class="notes">
193+
194+
</section>
195+
196+
<!-- /.notes -->
197+
198+
<!-- C API usage examples. -->
199+
200+
<section class="examples">
201+
202+
### Examples
203+
204+
```c
205+
#include "stdlib/complex/float64/base/neg.h"
206+
#include "stdlib/complex/float64/ctor.h"
207+
#include "stdlib/complex/float64/reim.h"
208+
#include <stdio.h>
209+
210+
int main( void ) {
211+
const stdlib_complex128_t x[] = {
212+
stdlib_complex128( 3.14, 1.5 ),
213+
stdlib_complex128( -3.14, 1.5 ),
214+
stdlib_complex128( 0.0, -0.0 ),
215+
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
216+
};
217+
218+
stdlib_complex128_t v;
219+
stdlib_complex128_t y;
220+
double re;
221+
double im;
222+
int i;
223+
for ( i = 0; i < 4; i++ ) {
224+
v = x[ i ];
225+
stdlib_complex128_reim( v, &re, &im );
226+
printf( "z = %lf + %lfi\n", re, im );
227+
228+
y = stdlib_base_complex128_neg( v );
229+
stdlib_complex128_reim( y, &re, &im );
230+
printf( "cneg(z) = %lf + %lfi\n", re, im );
231+
}
232+
}
233+
```
234+
235+
</section>
236+
237+
<!-- /.examples -->
238+
239+
</section>
240+
241+
<!-- /.c -->
242+
243+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
244+
245+
<section class="references">
246+
247+
</section>
248+
249+
<!-- /.references -->
250+
251+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
252+
253+
<section class="related">
254+
255+
* * *
256+
257+
## See Also
258+
259+
- <span class="package-name">[`@stdlib/math/base/special/cabs`][@stdlib/math/base/special/cabs]</span><span class="delimiter">: </span><span class="description">compute the absolute value of a double-precision complex floating-point number.</span>
260+
261+
</section>
262+
263+
<!-- /.related -->
264+
265+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
266+
267+
<section class="links">
268+
269+
<!-- <related-links> -->
270+
271+
[@stdlib/math/base/special/cabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cabs
272+
273+
<!-- </related-links> -->
274+
275+
</section>
276+
277+
<!-- /.links -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 Complex128 = require( '@stdlib/complex/float64/ctor' );
25+
var isComplex128 = require( '@stdlib/assert/is-complex128' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
27+
var pkg = require( './../package.json' ).name;
28+
var cneg = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var values;
35+
var z;
36+
var y;
37+
var i;
38+
39+
values = [
40+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
41+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
42+
];
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
z = values[ i%values.length ];
47+
y = cneg( z );
48+
if ( typeof y !== 'object' ) {
49+
b.fail( 'should return an object' );
50+
}
51+
}
52+
b.toc();
53+
if ( !isComplex128( y ) ) {
54+
b.fail( 'should return a Complex128' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});

0 commit comments

Comments
 (0)