diff --git a/base/special/cphase/README.md b/base/special/cphase/README.md index 0b93f1b30..a64269cb5 100644 --- a/base/special/cphase/README.md +++ b/base/special/cphase/README.md @@ -20,7 +20,7 @@ limitations under the License. # cphase -> Compute the [argument][complex-number-argument] of a complex number in radians. +> Compute the [argument][complex-number-argument] of a double-precision complex floating-point number in radians.
@@ -38,12 +38,14 @@ The [argument][complex-number-argument] of a complex number, also known as the * var cphase = require( '@stdlib/math/base/special/cphase' ); ``` -#### cphase( re, im ) +#### cphase( z ) -Computes the [argument][complex-number-argument] of a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`. +Computes the [argument][complex-number-argument] of a double-precision complex floating-point number. ```javascript -var phi = cphase( 5.0, 3.0 ); +var Complex128 = require( '@stdlib/complex/float64' ); + +var phi = cphase( new Complex128( 5.0, 3.0 ) ); // returns ~0.5404 ``` @@ -59,22 +61,116 @@ var phi = cphase( 5.0, 3.0 ); ```javascript var Complex128 = require( '@stdlib/complex/float64' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var real = require( '@stdlib/complex/real' ); -var imag = require( '@stdlib/complex/imag' ); +var uniform = require( '@stdlib/random/base/uniform' ); var cphase = require( '@stdlib/math/base/special/cphase' ); -var re; -var im; var z; var i; for ( i = 0; i < 100; i++ ) { - re = round( randu()*100.0 ) - 50.0; - im = round( randu()*100.0 ) - 50.0; - z = new Complex128( re, im ); - console.log( 'arg(%s) = %d', z.toString(), cphase( real(z), imag(z) ) ); + z = new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ); + console.log( 'arg(%s) = %d', z.toString(), cphase( z ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/cphase.h" +``` + +#### stdlib_base_cphase( z ) + +Computes the [argument][complex-number-argument] of a double-precision complex floating-point number. + +```c +#include "stdlib/complex/float64.h" +#include "stdlib/complex/real.h" +#include "stdlib/complex/imag.h" + +stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); +double out = stdlib_base_cphase( z ); +// returns ~0.5404 +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex128_t` input value. + +```c +double stdlib_base_cphase( const stdlib_complex128_t z ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/cphase.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/reim.h" +#include + +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 re1; + double im1; + double re2; + double im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_cphase( v ); + stdlib_reim( v, &re1, &im1 ); + stdlib_reim( y, &re2, &im2 ); + printf( "cphase(%lf + %lfi) = %lf\n", re, im, y ); + } } ``` @@ -82,6 +178,10 @@ for ( i = 0; i < 100; i++ ) { +
+ + +