|
| 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 --> |
0 commit comments