@stdlib/complex-float64-base-sub
v0.1.1
Published
Subtract two double-precision complex floating-point numbers.
Readme
csub
Subtract two double-precision complex floating-point numbers.
Installation
npm install @stdlib/complex-float64-base-subUsage
var csub = require( '@stdlib/complex-float64-base-sub' );csub( z1, z2 )
Subtracts two double-precision complex floating-point numbers.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var z1 = new Complex128( 5.0, 3.0 );
var z2 = new Complex128( -2.0, 1.0 );
var v = csub( z1, z2 );
// returns <Complex128>[ 7.0, 2.0 ]Examples
var Complex128Array = require( '@stdlib/array-complex128' );
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var csub = require( '@stdlib/complex-float64-base-sub' );
// Generate arrays of random values:
var z1 = new Complex128Array( discreteUniform( 200, -50, 50 ) );
var z2 = new Complex128Array( discreteUniform( 200, -50, 50 ) );
// Perform element-wise subtraction:
logEachMap( '(%s) - (%s) = %s', z1, z2, csub );C APIs
Usage
#include "stdlib/complex/float64/base/sub.h"stdlib_base_complex128_sub( z1, z2 )
Subtracts two double-precision complex floating-point numbers.
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/complex/float64/real.h"
#include "stdlib/complex/float64/imag.h"
stdlib_complex128_t z1 = stdlib_complex128( 5.0, 3.0 );
stdlib_complex128_t z2 = stdlib_complex128( -2.0, 1.0 );
stdlib_complex128_t out = stdlib_base_complex128_sub( z1, z2 );
double re = stdlib_complex128_real( out );
// returns 7.0
double im = stdlib_complex128_imag( out );
// returns 2.0The function accepts the following arguments:
- z1:
[in] stdlib_complex128_tinput value. - z2:
[in] stdlib_complex128_tinput value.
stdlib_complex128_t stdlib_base_complex128_sub( const stdlib_complex128_t z1, const stdlib_complex128_t z2 );Examples
#include "stdlib/complex/float64/base/sub.h"
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/complex/float64/reim.h"
#include <stdio.h>
int main( void ) {
const stdlib_complex128_t x[] = {
stdlib_complex128( 3.14, 1.5 ),
stdlib_complex128( -3.14, 1.5 ),
stdlib_complex128( 0.0, -0.0 ),
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
};
stdlib_complex128_t v;
stdlib_complex128_t y;
double re;
double im;
int i;
for ( i = 0; i < 4; i++ ) {
v = x[ i ];
stdlib_complex128_reim( v, &re, &im );
printf( "z = %lf + %lfi\n", re, im );
y = stdlib_base_complex128_sub( v, v );
stdlib_complex128_reim( y, &re, &im );
printf( "csub(z, z) = %lf + %lfi\n", re, im );
}
}See Also
@stdlib/complex-float64/base/add: add two double-precision complex floating-point numbers.@stdlib/complex-float64/base/div: divide two complex numbers.@stdlib/complex-float64/base/mul: multiply two double-precision complex floating-point numbers.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
