|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# add4 |
| 22 | + |
| 23 | +> Compute the sum of four 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 add4 = require( '@stdlib/complex/float64/base/add4' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### add4( z1, z2, z3, z4 ) |
| 40 | + |
| 41 | +Computes the sum of four double-precision complex floating-point numbers. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 45 | + |
| 46 | +var z = new Complex128( -1.5, 2.5 ); |
| 47 | + |
| 48 | +var v = add4( z, z, z, z ); |
| 49 | +// returns <Complex128>[ -7.5, 12.5 ] |
| 50 | +``` |
| 51 | + |
| 52 | +The function supports the following parameters: |
| 53 | + |
| 54 | +- **z1**: first complex number. |
| 55 | +- **z2**: second complex number. |
| 56 | +- **z3**: third complex number. |
| 57 | +- **z4**: fourth complex number. |
| 58 | + |
| 59 | +#### add4.assign( re1, im1, re2, im2, re3, im3, re4, im4, out, strideOut, offsetOut ) |
| 60 | + |
| 61 | +Computes the sum of four double-precision complex floating-point numbers and assigns results to a provided output array. |
| 62 | + |
| 63 | +```javascript |
| 64 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 65 | + |
| 66 | +var out = new Float64Array( 2 ); |
| 67 | +var v = add4.assign( 5.0, 3.0, -2.0, 1.0, 5.0, 3.0, 1.0, 4.0, out, 1, 0 ); |
| 68 | +// returns <Float64Array>[ 9.0, 11.0 ] |
| 69 | + |
| 70 | +var bool = ( out === v ); |
| 71 | +// returns true |
| 72 | +``` |
| 73 | + |
| 74 | +The function supports the following parameters: |
| 75 | + |
| 76 | +- **re1**: real component of the first complex number. |
| 77 | +- **im1**: imaginary component of the first complex number. |
| 78 | +- **re2**: real component of the second complex number. |
| 79 | +- **im2**: imaginary component of the second complex number. |
| 80 | +- **re3**: real component of the third complex number. |
| 81 | +- **im3**: imaginary component of the third complex number. |
| 82 | +- **re4**: real component of the fourth complex number. |
| 83 | +- **im4**: imaginary component of the fourth complex number. |
| 84 | +- **out**: output array. |
| 85 | +- **strideOut**: stride length for `out`. |
| 86 | +- **offsetOut**: starting index for `out`. |
| 87 | + |
| 88 | +#### add4.strided( z1, sz1, oz1, z2, sz2, oz2, z3, sz3, oz3, z4, sz4, oz4, out, so, oo ) |
| 89 | + |
| 90 | +Computes the sum of four double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array. |
| 91 | + |
| 92 | +```javascript |
| 93 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 94 | + |
| 95 | +var z1 = new Float64Array( [ 5.0, 3.0 ] ); |
| 96 | +var z2 = new Float64Array( [ -2.0, 1.0 ] ); |
| 97 | +var z3 = new Float64Array( [ 5.0, 3.0 ] ); |
| 98 | +var z4 = new Float64Array( [ 1.0, 4.0 ] ); |
| 99 | +var out = new Float64Array( 2 ); |
| 100 | + |
| 101 | +var v = add4.strided( z1, 1, 0, z2, 1, 0, z3, 1, 0, z4, 1, 0, out, 1, 0 ); |
| 102 | +// returns <Float64Array>[ 9.0, 11.0 ] |
| 103 | + |
| 104 | +var bool = ( out === v ); |
| 105 | +// returns true |
| 106 | +``` |
| 107 | + |
| 108 | +The function supports the following parameters: |
| 109 | + |
| 110 | +- **z1**: first complex number strided array view. |
| 111 | +- **sz1**: stride length for `z1`. |
| 112 | +- **oz1**: starting index for `z1`. |
| 113 | +- **z2**: second complex number strided array view. |
| 114 | +- **sz2**: stride length for `z2`. |
| 115 | +- **oz2**: starting index for `z2`. |
| 116 | +- **z3**: third complex number strided array view. |
| 117 | +- **sz3**: stride length for `z3`. |
| 118 | +- **oz3**: starting index for `z3`. |
| 119 | +- **z4**: fourth complex number strided array view. |
| 120 | +- **sz4**: stride length for `z4`. |
| 121 | +- **oz4**: starting index for `z4`. |
| 122 | +- **out**: output array. |
| 123 | +- **so**: stride length for `out`. |
| 124 | +- **oo**: starting index for `out`. |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.usage --> |
| 129 | + |
| 130 | +<section class="examples"> |
| 131 | + |
| 132 | +## Examples |
| 133 | + |
| 134 | +<!-- eslint no-undef: "error" --> |
| 135 | + |
| 136 | +```javascript |
| 137 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 138 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 139 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 140 | +var add4 = require( '@stdlib/complex/float64/base/add4' ); |
| 141 | + |
| 142 | +// Generate arrays of random values: |
| 143 | +var z1 = new Complex128Array( discreteUniform( 200, -50, 50 ) ); |
| 144 | +var z2 = new Complex128Array( discreteUniform( 200, -50, 50 ) ); |
| 145 | +var z3 = new Complex128Array( discreteUniform( 200, -50, 50 ) ); |
| 146 | +var z4 = new Complex128Array( discreteUniform( 200, -50, 50 ) ); |
| 147 | + |
| 148 | +// Perform element-wise addition: |
| 149 | +logEachMap( '(%s) + (%s) + (%s) + (%s) = %s', z1, z2, z3, z4, add4 ); |
| 150 | +``` |
| 151 | + |
| 152 | +</section> |
| 153 | + |
| 154 | +<!-- /.examples --> |
| 155 | + |
| 156 | +<!-- C interface documentation. --> |
| 157 | + |
| 158 | +* * * |
| 159 | + |
| 160 | +<section class="c"> |
| 161 | + |
| 162 | +## C APIs |
| 163 | + |
| 164 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 165 | + |
| 166 | +<section class="intro"> |
| 167 | + |
| 168 | +</section> |
| 169 | + |
| 170 | +<!-- /.intro --> |
| 171 | + |
| 172 | +<!-- C usage documentation. --> |
| 173 | + |
| 174 | +<section class="usage"> |
| 175 | + |
| 176 | +### Usage |
| 177 | + |
| 178 | +```c |
| 179 | +#include "stdlib/complex/float64/base/add4.h" |
| 180 | +``` |
| 181 | + |
| 182 | +#### stdlib_base_complex128_add4( z1, z2, z3, z4 ) |
| 183 | + |
| 184 | +Computes the sum of four double-precision complex floating-point numbers. |
| 185 | + |
| 186 | +```c |
| 187 | +#include "stdlib/complex/float64/ctor.h" |
| 188 | +#include "stdlib/complex/float64/real.h" |
| 189 | +#include "stdlib/complex/float64/imag.h" |
| 190 | + |
| 191 | +stdlib_complex128_t z = stdlib_complex128( 3.0, -2.0 ); |
| 192 | + |
| 193 | +stdlib_complex128_t out = stdlib_base_complex128_add4( z, z, z, z ); |
| 194 | + |
| 195 | +double re = stdlib_complex128_real( out ); |
| 196 | +// returns 12.0 |
| 197 | + |
| 198 | +double im = stdlib_complex128_imag( out ); |
| 199 | +// returns -8.0 |
| 200 | +``` |
| 201 | + |
| 202 | +The function accepts the following arguments: |
| 203 | + |
| 204 | +- **z1**: `[in] stdlib_complex128_t` first input value. |
| 205 | +- **z2**: `[in] stdlib_complex128_t` second input value. |
| 206 | +- **z3**: `[in] stdlib_complex128_t` third input value. |
| 207 | +- **z4**: `[in] stdlib_complex128_t` fourth input value. |
| 208 | + |
| 209 | +```c |
| 210 | +stdlib_complex128_t stdlib_base_complex128_add4( const stdlib_complex128_t z1, const stdlib_complex128_t z2, const stdlib_complex128_t z3, const stdlib_complex128_t z4 ); |
| 211 | +``` |
| 212 | +
|
| 213 | +</section> |
| 214 | +
|
| 215 | +<!-- /.usage --> |
| 216 | +
|
| 217 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 218 | +
|
| 219 | +<section class="notes"> |
| 220 | +
|
| 221 | +</section> |
| 222 | +
|
| 223 | +<!-- /.notes --> |
| 224 | +
|
| 225 | +<!-- C API usage examples. --> |
| 226 | +
|
| 227 | +<section class="examples"> |
| 228 | +
|
| 229 | +### Examples |
| 230 | +
|
| 231 | +```c |
| 232 | +#include "stdlib/complex/float64/base/add4.h" |
| 233 | +#include "stdlib/complex/float64/ctor.h" |
| 234 | +#include "stdlib/complex/float64/reim.h" |
| 235 | +#include <stdio.h> |
| 236 | +
|
| 237 | +int main( void ) { |
| 238 | + const stdlib_complex128_t x[] = { |
| 239 | + stdlib_complex128( 3.14, 1.5 ), |
| 240 | + stdlib_complex128( -3.14, 1.5 ), |
| 241 | + stdlib_complex128( 0.0, -0.0 ), |
| 242 | + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) |
| 243 | + }; |
| 244 | +
|
| 245 | + stdlib_complex128_t v; |
| 246 | + stdlib_complex128_t y; |
| 247 | + double re; |
| 248 | + double im; |
| 249 | + int i; |
| 250 | + for ( i = 0; i < 4; i++ ) { |
| 251 | + v = x[ i ]; |
| 252 | + stdlib_complex128_reim( v, &re, &im ); |
| 253 | + printf( "z = %lf + %lfi\n", re, im ); |
| 254 | +
|
| 255 | + y = stdlib_base_complex128_add4( v, v, v, v ); |
| 256 | + stdlib_complex128_reim( y, &re, &im ); |
| 257 | + printf( "add4(z, z, z, z) = %lf + %lfi\n", re, im ); |
| 258 | + } |
| 259 | +} |
| 260 | +``` |
| 261 | + |
| 262 | +</section> |
| 263 | + |
| 264 | +<!-- /.examples --> |
| 265 | + |
| 266 | +</section> |
| 267 | + |
| 268 | +<!-- /.c --> |
| 269 | + |
| 270 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 271 | + |
| 272 | +<section class="related"> |
| 273 | + |
| 274 | +</section> |
| 275 | + |
| 276 | +<!-- /.related --> |
| 277 | + |
| 278 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 279 | + |
| 280 | +<section class="links"> |
| 281 | + |
| 282 | +</section> |
| 283 | + |
| 284 | +<!-- /.links --> |
0 commit comments