@stdlib/math-base-special-cpolarf
v0.1.1
Published
Compute the absolute value and the phase of a single-precision complex floating-point number.
Readme
cpolarf
Compute the absolute value and phase of a single-precision complex floating-point number.
Installation
npm install @stdlib/math-base-special-cpolarfUsage
var cpolarf = require( '@stdlib/math-base-special-cpolarf' );cpolarf( z )
Computes the absolute value and phase of a single-precision complex floating-point number.
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var o = cpolarf( new Complex64( 5.0, 3.0 ) );
// returns [ ~5.83, ~0.5404 ]cpolarf.assign( z, out, stride, offset )
Computes the absolute value and phase of a single-precision complex floating-point number and assigns results to a provided output array.
var Complex64 = require( '@stdlib/complex-float32-ctor' );
var Float32Array = require( '@stdlib/array-float32' );
var out = new Float32Array( 2 );
var v = cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 );
// returns <Float32Array>[ ~5.83, ~0.5404 ]
var bool = ( v === out );
// returns trueExamples
var Complex64Array = require( '@stdlib/array-complex64' );
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var cpolarf = require( '@stdlib/math-base-special-cpolarf' );
// Create an array of random numbers:
var opts = {
'dtype': 'float32'
};
var arr = new Complex64Array( uniform( 200, -100.0, 100.0, opts ) );
// Compute the polar form of each number in the array:
logEachMap( 'cpolarf(%s) = [%s]', arr, cpolarf );C APIs
Usage
#include "stdlib/math/base/special/cpolarf.h"stdlib_base_cpolarf( z, cabsf, cphasef )
Computes the absolute value and phase of a single-precision complex floating-point number.
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/float32/real.h"
#include "stdlib/complex/float32/imag.h"
stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f );
float cabsf;
float cphasef;
stdlib_base_cpolarf( z, &cabsf, &cphasef );The function accepts the following arguments:
- z:
[in] stdlib_complex64_tinput value. - cabsf:
[out] float*destination for the absolute value. - cphasef:
[out] float*destination for the phase value in radians.
void stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef );Examples
#include "stdlib/math/base/special/cpolarf.h"
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/float32/reim.h"
#include <stdio.h>
int main( void ) {
const stdlib_complex64_t x[] = {
stdlib_complex64( 3.14f, 1.0f ),
stdlib_complex64( -3.14f, -1.0f ),
stdlib_complex64( 0.0f, 0.0f ),
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
};
float cphasef;
float cabsf;
float re;
float im;
int i;
for ( i = 0; i < 4; i++ ) {
stdlib_base_cpolarf( x[i], &cabsf, &cphasef );
stdlib_complex64_reim( x[i], &re, &im );
printf( "cpolarf(%f + %fi) => cabsf: %f, cphasef: %f\n", re, im, cabsf, cphasef );
}
}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.
