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