|
| 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 | +# mul |
| 22 | + |
| 23 | +> Multiply 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 mul = require( '@stdlib/complex/float64/base/mul' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### mul( z1, z2 ) |
| 40 | + |
| 41 | +Multiplies 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( 5.0, 3.0 ); |
| 49 | +var z2 = new Complex128( -2.0, 1.0 ); |
| 50 | + |
| 51 | +var v = mul( z1, z2 ); |
| 52 | +// returns <Complex128> |
| 53 | + |
| 54 | +var re = real( v ); |
| 55 | +// returns -13.0 |
| 56 | + |
| 57 | +var im = imag( v ); |
| 58 | +// returns -1.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' ).factory; |
| 74 | +var mul = require( '@stdlib/complex/float64/base/mul' ); |
| 75 | + |
| 76 | +var rand = discreteUniform( -50, 50 ); |
| 77 | + |
| 78 | +var z1; |
| 79 | +var z2; |
| 80 | +var z3; |
| 81 | +var i; |
| 82 | +for ( i = 0; i < 100; i++ ) { |
| 83 | + z1 = new Complex128( rand(), rand() ); |
| 84 | + z2 = new Complex128( rand(), rand() ); |
| 85 | + z3 = mul( z1, z2 ); |
| 86 | + console.log( '(%s) * (%s) = %s', z1.toString(), z2.toString(), z3.toString() ); |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +</section> |
| 91 | + |
| 92 | +<!-- /.examples --> |
| 93 | + |
| 94 | +<!-- C interface documentation. --> |
| 95 | + |
| 96 | +* * * |
| 97 | + |
| 98 | +<section class="c"> |
| 99 | + |
| 100 | +## C APIs |
| 101 | + |
| 102 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 103 | + |
| 104 | +<section class="intro"> |
| 105 | + |
| 106 | +</section> |
| 107 | + |
| 108 | +<!-- /.intro --> |
| 109 | + |
| 110 | +<!-- C usage documentation. --> |
| 111 | + |
| 112 | +<section class="usage"> |
| 113 | + |
| 114 | +### Usage |
| 115 | + |
| 116 | +```c |
| 117 | +#include "stdlib/complex/float64/base/mul.h" |
| 118 | +``` |
| 119 | + |
| 120 | +#### stdlib_base_complex128_mul( z1, z2 ) |
| 121 | + |
| 122 | +Multiplies two double-precision complex floating-point numbers. |
| 123 | + |
| 124 | +```c |
| 125 | +#include "stdlib/complex/float64/ctor.h" |
| 126 | +#include "stdlib/complex/float64/real.h" |
| 127 | +#include "stdlib/complex/float64/imag.h" |
| 128 | + |
| 129 | +stdlib_complex128_t z1 = stdlib_complex128( 5.0, 3.0 ); |
| 130 | +stdlib_complex128_t z2 = stdlib_complex128( -2.0, 1.0 ); |
| 131 | + |
| 132 | +stdlib_complex128_t out = stdlib_base_complex128_mul( z1, z2 ); |
| 133 | + |
| 134 | +double re = stdlib_complex128_real( out ); |
| 135 | +// returns -13.0 |
| 136 | + |
| 137 | +double im = stdlib_complex128_imag( out ); |
| 138 | +// returns -1.0 |
| 139 | +``` |
| 140 | + |
| 141 | +The function accepts the following arguments: |
| 142 | + |
| 143 | +- **z1**: `[in] stdlib_complex128_t` input value. |
| 144 | +- **z2**: `[in] stdlib_complex128_t` input value. |
| 145 | + |
| 146 | +```c |
| 147 | +stdlib_complex128_t stdlib_base_complex128_mul( const stdlib_complex128_t z1, const stdlib_complex128_t z2 ); |
| 148 | +``` |
| 149 | +
|
| 150 | +</section> |
| 151 | +
|
| 152 | +<!-- /.usage --> |
| 153 | +
|
| 154 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 155 | +
|
| 156 | +<section class="notes"> |
| 157 | +
|
| 158 | +</section> |
| 159 | +
|
| 160 | +<!-- /.notes --> |
| 161 | +
|
| 162 | +<!-- C API usage examples. --> |
| 163 | +
|
| 164 | +<section class="examples"> |
| 165 | +
|
| 166 | +### Examples |
| 167 | +
|
| 168 | +```c |
| 169 | +#include "stdlib/complex/float64/base/mul.h" |
| 170 | +#include "stdlib/complex/float64/ctor.h" |
| 171 | +#include "stdlib/complex/float64/reim.h" |
| 172 | +#include <stdio.h> |
| 173 | +
|
| 174 | +int main( void ) { |
| 175 | + const stdlib_complex128_t x[] = { |
| 176 | + stdlib_complex128( 3.14, 1.5 ), |
| 177 | + stdlib_complex128( -3.14, 1.5 ), |
| 178 | + stdlib_complex128( 0.0, -0.0 ), |
| 179 | + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) |
| 180 | + }; |
| 181 | +
|
| 182 | + stdlib_complex128_t v; |
| 183 | + stdlib_complex128_t y; |
| 184 | + double re; |
| 185 | + double im; |
| 186 | + int i; |
| 187 | + for ( i = 0; i < 4; i++ ) { |
| 188 | + v = x[ i ]; |
| 189 | + stdlib_complex128_reim( v, &re, &im ); |
| 190 | + printf( "z = %lf + %lfi\n", re, im ); |
| 191 | +
|
| 192 | + y = stdlib_base_complex128_mul( v, v ); |
| 193 | + stdlib_complex128_reim( y, &re, &im ); |
| 194 | + printf( "mul(z, z) = %lf + %lfi\n", re, im ); |
| 195 | + } |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +</section> |
| 200 | + |
| 201 | +<!-- /.examples --> |
| 202 | + |
| 203 | +</section> |
| 204 | + |
| 205 | +<!-- /.c --> |
| 206 | + |
| 207 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 208 | + |
| 209 | +<section class="related"> |
| 210 | + |
| 211 | +* * * |
| 212 | + |
| 213 | +## See Also |
| 214 | + |
| 215 | +- <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> |
| 216 | +- <span class="package-name">[`@stdlib/math/base/ops/cdiv`][@stdlib/math/base/ops/cdiv]</span><span class="delimiter">: </span><span class="description">divide two complex numbers.</span> |
| 217 | +- <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> |
| 218 | + |
| 219 | +</section> |
| 220 | + |
| 221 | +<!-- /.related --> |
| 222 | + |
| 223 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 224 | + |
| 225 | +<section class="links"> |
| 226 | + |
| 227 | +<!-- <related-links> --> |
| 228 | + |
| 229 | +[@stdlib/complex/float64/base/add]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/base/add |
| 230 | + |
| 231 | +[@stdlib/math/base/ops/cdiv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/ops/cdiv |
| 232 | + |
| 233 | +[@stdlib/math/base/ops/csub]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/ops/csub |
| 234 | + |
| 235 | +<!-- </related-links> --> |
| 236 | + |
| 237 | +</section> |
| 238 | + |
| 239 | +<!-- /.links --> |
0 commit comments