README.md (3283B)
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 # Flipsign 22 23 > Return a complex number with the same magnitude as `z` and the sign of `y*z`. 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 cflipsign = require( '@stdlib/math/base/special/cflipsign' ); 41 ``` 42 43 #### cflipsign( \[out,] re, im, y ) 44 45 Returns a complex number with the same magnitude as `z` and the sign of `y*z`. 46 47 ```javascript 48 var v = cflipsign( -4.2, 5.5, -4 ); 49 // returns [ 4.2, -5.5 ] 50 51 v = cflipsign( 0.0, 0.0, 5 ); 52 // returns [ 0.0, 0.0 ] 53 54 v = cflipsign( NaN, NaN, 6 ); 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 = cflipsign( out, -4.2, 5.5, 77 ); 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 cflipsign = require( '@stdlib/math/base/special/cflipsign' ); 98 99 var re; 100 var im; 101 var z; 102 var o; 103 var w; 104 var i; 105 var y; 106 107 for ( i = 0; i < 100; i++ ) { 108 re = ( randu()*100.0 ) - 50.0; 109 im = ( randu()*100.0 ) - 50.0; 110 y = ( randu()*100.0 ) - 50.0; 111 z = new Complex128( re, im ); 112 o = cflipsign( real(z), imag(z), y ); 113 w = new Complex128( o[ 0 ], o[ 1 ] ); 114 console.log( 'flipsign(%s) = %s', z.toString(), w.toString() ); 115 } 116 ``` 117 118 </section> 119 120 <!-- /.examples --> 121 122 <!-- 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. --> 123 124 <section class="references"> 125 126 </section> 127 128 <!-- /.references --> 129 130 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 131 132 <section class="links"> 133 134 </section> 135 136 <!-- /.links -->