README.md (2514B)
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 # subtract 22 23 > Subtract two complex 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 csub = require( '@stdlib/math/base/ops/csub' ); 37 ``` 38 39 #### csub( \[out,] re1, im1, re2, im2 ) 40 41 Subtracts two `complex` numbers where each `complex` number is comprised of a **real** component `re` and an **imaginary** component `im`. 42 43 ```javascript 44 var v = csub( 5.0, 3.0, -2.0, 1.0 ); 45 // returns [ 7.0, 2.0 ] 46 ``` 47 48 By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. 49 50 ```javascript 51 var Float64Array = require( '@stdlib/array/float64' ); 52 53 var out = new Float64Array( 2 ); 54 55 var v = csub( out, 5.0, 3.0, -2.0, 1.0 ); 56 // returns <Float64Array>[ 7.0, 2.0 ] 57 58 var bool = ( v === out ); 59 // returns true 60 ``` 61 62 </section> 63 64 <!-- /.usage --> 65 66 <section class="examples"> 67 68 ## Examples 69 70 <!-- eslint no-undef: "error" --> 71 72 ```javascript 73 var Complex128 = require( '@stdlib/complex/float64' ); 74 var randu = require( '@stdlib/random/base/randu' ); 75 var round = require( '@stdlib/math/base/special/round' ); 76 var real = require( '@stdlib/complex/real' ); 77 var imag = require( '@stdlib/complex/imag' ); 78 var csub = require( '@stdlib/math/base/ops/csub' ); 79 80 var re; 81 var im; 82 var z1; 83 var z2; 84 var z3; 85 var o; 86 var i; 87 88 for ( i = 0; i < 100; i++ ) { 89 re = round( randu()*100.0 ) - 50.0; 90 im = round( randu()*100.0 ) - 50.0; 91 z1 = new Complex128( re, im ); 92 93 re = round( randu()*100.0 ) - 50.0; 94 im = round( randu()*100.0 ) - 50.0; 95 z2 = new Complex128( re, im ); 96 97 o = csub( real(z1), imag(z1), real(z2), imag(z2) ); 98 z3 = new Complex128( o[ 0 ], o[ 1 ] ); 99 100 console.log( '(%s) - (%s) = %s', z1.toString(), z2.toString(), z3.toString() ); 101 } 102 ``` 103 104 </section> 105 106 <!-- /.examples --> 107 108 <section class="links"> 109 110 </section> 111 112 <!-- /.links -->