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