|
| 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 | +# cdiv |
| 22 | + |
| 23 | +> Divide two double-precision complex floating-point 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/complex/float64/base/div' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### cdiv( z1, z2 ) |
| 40 | + |
| 41 | +Divides two double-precision complex floating-point numbers. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 45 | +var real = require( '@stdlib/complex/float64/real' ); |
| 46 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 47 | + |
| 48 | +var z1 = new Complex128( -13.0, -1.0 ); |
| 49 | +var z2 = new Complex128( -2.0, 1.0 ); |
| 50 | + |
| 51 | +var v = cdiv( z1, z2 ); |
| 52 | +// returns <Complex128> |
| 53 | + |
| 54 | +var re = real( v ); |
| 55 | +// returns 5.0 |
| 56 | + |
| 57 | +var im = imag( v ); |
| 58 | +// returns 3.0 |
| 59 | +``` |
| 60 | + |
| 61 | +</section> |
| 62 | + |
| 63 | +<!-- /.usage --> |
| 64 | + |
| 65 | +<section class="examples"> |
| 66 | + |
| 67 | +## Examples |
| 68 | + |
| 69 | +<!-- eslint no-undef: "error" --> |
| 70 | + |
| 71 | +```javascript |
| 72 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 73 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 74 | +var real = require( '@stdlib/complex/float64/real' ); |
| 75 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 76 | +var cdiv = require( '@stdlib/complex/float64/base/div' ); |
| 77 | + |
| 78 | +function randomComplex() { |
| 79 | + var re = discreteUniform( -50, 50 ); |
| 80 | + var im = discreteUniform( -50, 50 ); |
| 81 | + return new Complex128( re, im ); |
| 82 | +} |
| 83 | + |
| 84 | +var z1; |
| 85 | +var z2; |
| 86 | +var z3; |
| 87 | +var i; |
| 88 | +for ( i = 0; i < 100; i++ ) { |
| 89 | + z1 = randomComplex(); |
| 90 | + z2 = randomComplex(); |
| 91 | + z3 = cdiv( z1, z2 ); |
| 92 | + console.log( '(%s) / (%s) = %s', z1.toString(), z2.toString(), z3.toString() ); |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +</section> |
| 97 | + |
| 98 | +<!-- /.examples --> |
| 99 | + |
| 100 | +<!-- C interface documentation. --> |
| 101 | + |
| 102 | +* * * |
| 103 | + |
| 104 | +<section class="c"> |
| 105 | + |
| 106 | +## C APIs |
| 107 | + |
| 108 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 109 | + |
| 110 | +<section class="intro"> |
| 111 | + |
| 112 | +</section> |
| 113 | + |
| 114 | +<!-- /.intro --> |
| 115 | + |
| 116 | +<!-- C usage documentation. --> |
| 117 | + |
| 118 | +<section class="usage"> |
| 119 | + |
| 120 | +### Usage |
| 121 | + |
| 122 | +```c |
| 123 | +#include "stdlib/complex/float64/base/div.h" |
| 124 | +``` |
| 125 | + |
| 126 | +#### stdlib_base_complex128_div( z1, z2 ) |
| 127 | + |
| 128 | +Divides two double-precision complex floating-point numbers. |
| 129 | + |
| 130 | +```c |
| 131 | +#include "stdlib/complex/float64/ctor.h" |
| 132 | +#include "stdlib/complex/float64/real.h" |
| 133 | +#include "stdlib/complex/float64/imag.h" |
| 134 | + |
| 135 | +stdlib_complex128_t z1 = stdlib_complex128( -13.0, -1.0 ); |
| 136 | +stdlib_complex128_t z2 = stdlib_complex128( -2.0, 1.0 ); |
| 137 | + |
| 138 | +stdlib_complex128_t out = stdlib_base_complex128_div( z1, z2 ); |
| 139 | + |
| 140 | +double re = stdlib_complex128_real( out ); |
| 141 | +// returns 5.0 |
| 142 | + |
| 143 | +double im = stdlib_complex128_imag( out ); |
| 144 | +// returns 3.0 |
| 145 | +``` |
| 146 | + |
| 147 | +The function accepts the following arguments: |
| 148 | + |
| 149 | +- **z1**: `[in] stdlib_complex128_t` input value. |
| 150 | +- **z2**: `[in] stdlib_complex128_t` input value. |
| 151 | + |
| 152 | +```c |
| 153 | +stdlib_complex128_t stdlib_base_complex128_div( const stdlib_complex128_t z1, const stdlib_complex128_t z2 ); |
| 154 | +``` |
| 155 | +
|
| 156 | +</section> |
| 157 | +
|
| 158 | +<!-- /.usage --> |
| 159 | +
|
| 160 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 161 | +
|
| 162 | +<section class="notes"> |
| 163 | +
|
| 164 | +</section> |
| 165 | +
|
| 166 | +<!-- /.notes --> |
| 167 | +
|
| 168 | +<!-- C API usage examples. --> |
| 169 | +
|
| 170 | +<section class="examples"> |
| 171 | +
|
| 172 | +### Examples |
| 173 | +
|
| 174 | +```c |
| 175 | +#include "stdlib/complex/float64/base/div.h" |
| 176 | +#include "stdlib/complex/float64/ctor.h" |
| 177 | +#include "stdlib/complex/float64/reim.h" |
| 178 | +#include <stdio.h> |
| 179 | +
|
| 180 | +int main( void ) { |
| 181 | + const stdlib_complex128_t x[] = { |
| 182 | + stdlib_complex128( 3.14, 1.5 ), |
| 183 | + stdlib_complex128( -3.14, 1.5 ), |
| 184 | + stdlib_complex128( 0.0, -0.0 ), |
| 185 | + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) |
| 186 | + }; |
| 187 | +
|
| 188 | + stdlib_complex128_t v; |
| 189 | + stdlib_complex128_t y; |
| 190 | + double re; |
| 191 | + double im; |
| 192 | + int i; |
| 193 | + for ( i = 0; i < 4; i++ ) { |
| 194 | + v = x[ i ]; |
| 195 | + stdlib_complex128_reim( v, &re, &im ); |
| 196 | + printf( "z = %lf + %lfi\n", re, im ); |
| 197 | +
|
| 198 | + y = stdlib_base_complex128_div( v, v ); |
| 199 | + stdlib_complex128_reim( y, &re, &im ); |
| 200 | + printf( "cdiv(z, z) = %lf + %lfi\n", re, im ); |
| 201 | + } |
| 202 | +} |
| 203 | +``` |
| 204 | + |
| 205 | +</section> |
| 206 | + |
| 207 | +<!-- /.examples --> |
| 208 | + |
| 209 | +</section> |
| 210 | + |
| 211 | +<!-- /.c --> |
| 212 | + |
| 213 | +* * * |
| 214 | + |
| 215 | +<section class="references"> |
| 216 | + |
| 217 | +## References |
| 218 | + |
| 219 | +- 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]. |
| 220 | +- 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]. |
| 221 | +- 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]. |
| 222 | +- 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]. |
| 223 | + |
| 224 | +</section> |
| 225 | + |
| 226 | +<!-- /.references --> |
| 227 | + |
| 228 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 229 | + |
| 230 | +<section class="related"> |
| 231 | + |
| 232 | +* * * |
| 233 | + |
| 234 | +## See Also |
| 235 | + |
| 236 | +- <span class="package-name">[`@stdlib/complex/float64/base/add`][@stdlib/complex/float64/base/add]</span><span class="delimiter">: </span><span class="description">add two double-precision complex floating-point numbers.</span> |
| 237 | +- <span class="package-name">[`@stdlib/complex/float64/base/mul`][@stdlib/complex/float64/base/mul]</span><span class="delimiter">: </span><span class="description">multiply two double-precision complex floating-point numbers.</span> |
| 238 | +- <span class="package-name">[`@stdlib/math/base/ops/csub`][@stdlib/math/base/ops/csub]</span><span class="delimiter">: </span><span class="description">subtract two double-precision complex floating-point numbers.</span> |
| 239 | + |
| 240 | +</section> |
| 241 | + |
| 242 | +<!-- /.related --> |
| 243 | + |
| 244 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 245 | + |
| 246 | +<section class="links"> |
| 247 | + |
| 248 | +[@smith:1962a]: https://doi.org/10.1145/368637.368661 |
| 249 | + |
| 250 | +[@stewart:1985a]: https://doi.org/10.1145/214408.214414 |
| 251 | + |
| 252 | +[@priest:2004a]: https://doi.org/10.1145/1039813.1039814 |
| 253 | + |
| 254 | +[@baudin:2012a]: https://arxiv.org/abs/1210.4539 |
| 255 | + |
| 256 | +<!-- <related-links> --> |
| 257 | + |
| 258 | +[@stdlib/complex/float64/base/add]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/base/add |
| 259 | + |
| 260 | +[@stdlib/complex/float64/base/mul]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/base/mul |
| 261 | + |
| 262 | +[@stdlib/math/base/ops/csub]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/ops/csub |
| 263 | + |
| 264 | +<!-- </related-links> --> |
| 265 | + |
| 266 | +</section> |
| 267 | + |
| 268 | +<!-- /.links --> |
0 commit comments