README.md (3133B)
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 # Negate 22 23 > Negate a complex 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/math/base/ops/cneg' ); 41 ``` 42 43 #### cneg( \[out,] re, im ) 44 45 Negates a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`. 46 47 ```javascript 48 var v = cneg( -4.2, 5.5 ); 49 // returns [ 4.2, -5.5 ] 50 51 v = cneg( 0.0, 0.0 ); 52 // returns [ -0.0, -0.0 ] 53 54 v = cneg( NaN, NaN ); 55 // returns [ NaN, NaN ] 56 ``` 57 58 By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. 59 60 ```javascript 61 var Float64Array = require( '@stdlib/array/float64' ); 62 63 var out = new Float64Array( 2 ); 64 65 var v = cneg( out, -4.2, 5.5 ); 66 // returns <Float64Array>[ 4.2, -5.5 ] 67 68 var bool = ( v === out ); 69 // returns true 70 ``` 71 72 </section> 73 74 <!-- /.usage --> 75 76 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 77 78 <section class="notes"> 79 80 </section> 81 82 <!-- /.notes --> 83 84 <!-- Package usage examples. --> 85 86 <section class="examples"> 87 88 ## Examples 89 90 <!-- eslint no-undef: "error" --> 91 92 ```javascript 93 var Complex128 = require( '@stdlib/complex/float64' ); 94 var randu = require( '@stdlib/random/base/randu' ); 95 var real = require( '@stdlib/complex/real' ); 96 var imag = require( '@stdlib/complex/imag' ); 97 var cneg = require( '@stdlib/math/base/ops/cneg' ); 98 99 var re; 100 var im; 101 var z; 102 var o; 103 var w; 104 var i; 105 106 for ( i = 0; i < 100; i++ ) { 107 re = ( randu()*100.0 ) - 50.0; 108 im = ( randu()*100.0 ) - 50.0; 109 z = new Complex128( re, im ); 110 o = cneg( real(z), imag(z) ); 111 w = new Complex128( o[ 0 ], o[ 1 ] ); 112 console.log( 'negate(%s) = %s', z.toString(), w.toString() ); 113 } 114 ``` 115 116 </section> 117 118 <!-- /.examples --> 119 120 <!-- 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. --> 121 122 <section class="references"> 123 124 </section> 125 126 <!-- /.references --> 127 128 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 129 130 <section class="links"> 131 132 </section> 133 134 <!-- /.links -->