README.md (3523B)
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 # divide 22 23 > Divide two complex numbers. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var cdiv = require( '@stdlib/math/base/ops/cdiv' ); 37 ``` 38 39 #### cdiv( \[out,] re1, im1, re2, im2 ) 40 41 Divides two `complex` numbers where each `complex` number is comprised of a **real** component `re` and an **imaginary** component `im`. 42 43 ```javascript 44 var v = cdiv( -13.0, -1.0, -2.0, 1.0 ); 45 // returns [ 5.0, 3.0 ] 46 ``` 47 48 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. 49 50 ```javascript 51 var Float64Array = require( '@stdlib/array/float64' ); 52 53 var out = new Float64Array( 2 ); 54 55 var v = cdiv( out, -13.0, -1.0, -2.0, 1.0 ); 56 // returns <Float64Array>[ 5.0, 3.0 ] 57 58 var bool = ( v === out ); 59 // returns true 60 ``` 61 62 </section> 63 64 <!-- /.usage --> 65 66 <section class="examples"> 67 68 ## Examples 69 70 <!-- eslint no-undef: "error" --> 71 72 ```javascript 73 var Complex128 = require( '@stdlib/complex/float64' ); 74 var randu = require( '@stdlib/random/base/randu' ); 75 var round = require( '@stdlib/math/base/special/round' ); 76 var real = require( '@stdlib/complex/real' ); 77 var imag = require( '@stdlib/complex/imag' ); 78 var cdiv = require( '@stdlib/math/base/ops/cdiv' ); 79 80 var re; 81 var im; 82 var z1; 83 var z2; 84 var z3; 85 var o; 86 var i; 87 88 for ( i = 0; i < 100; i++ ) { 89 re = round( randu()*100.0 ) - 50.0; 90 im = round( randu()*100.0 ) - 50.0; 91 z1 = new Complex128( re, im ); 92 93 re = round( randu()*100.0 ) - 50.0; 94 im = round( randu()*100.0 ) - 50.0; 95 z2 = new Complex128( re, im ); 96 97 o = cdiv( real(z1), imag(z1), real(z2), imag(z2) ); 98 z3 = new Complex128( o[ 0 ], o[ 1 ] ); 99 100 console.log( '(%s) / (%s) = %s', z1.toString(), z2.toString(), z3.toString() ); 101 } 102 ``` 103 104 </section> 105 106 <!-- /.examples --> 107 108 * * * 109 110 <section class="references"> 111 112 ## References 113 114 - Smith, Robert L. 1962. "Algorithm 116: Complex Division." _Commun. ACM_ 5 (8). New York, NY, USA: ACM: 435. doi:[10.1145/368637.368661][@smith:1962a]. 115 - Stewart, G. W. 1985. "A Note on Complex Division." _ACM Trans. Math. Softw._ 11 (3). New York, NY, USA: ACM: 238–41. doi:[10.1145/214408.214414][@stewart:1985a]. 116 - Priest, Douglas M. 2004. "Efficient Scaling for Complex Division." _ACM Trans. Math. Softw._ 30 (4). New York, NY, USA: ACM: 389–401. doi:[10.1145/1039813.1039814][@priest:2004a]. 117 - Baudin, Michael, and Robert L. Smith. 2012. "A Robust Complex Division in Scilab." _arXiv_ abs/1210.4539 \[cs.MS] (October): 1–25. [<https://arxiv.org/abs/1210.4539>][@baudin:2012a]. 118 119 </section> 120 121 <!-- /.references --> 122 123 <section class="links"> 124 125 [@smith:1962a]: https://doi.org/10.1145/368637.368661 126 127 [@stewart:1985a]: https://doi.org/10.1145/214408.214414 128 129 [@priest:2004a]: https://doi.org/10.1145/1039813.1039814 130 131 [@baudin:2012a]: https://arxiv.org/abs/1210.4539 132 133 </section> 134 135 <!-- /.links -->