|
| 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 | +# cphasef |
| 22 | + |
| 23 | +> Compute the [argument][complex-number-argument] of a single-precision complex floating-point number in radians. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [argument][complex-number-argument] of a complex number, also known as the **phase**, is the angle of the radius extending from the origin to the complex number plotted in the complex plane and the positive real axis. |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<section class="usage"> |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +```javascript |
| 38 | +var cphasef = require( '@stdlib/math/base/special/cphasef' ); |
| 39 | +``` |
| 40 | + |
| 41 | +#### cphasef( z ) |
| 42 | + |
| 43 | +Computes the [argument][complex-number-argument] of a single-precision complex floating-point number. |
| 44 | + |
| 45 | +```javascript |
| 46 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 47 | + |
| 48 | +var phi = cphasef( new Complex64( 5.0, 3.0 ) ); |
| 49 | +// returns ~0.5404 |
| 50 | +``` |
| 51 | + |
| 52 | +</section> |
| 53 | + |
| 54 | +<!-- /.usage --> |
| 55 | + |
| 56 | +<section class="examples"> |
| 57 | + |
| 58 | +## Examples |
| 59 | + |
| 60 | +<!-- eslint no-undef: "error" --> |
| 61 | + |
| 62 | +```javascript |
| 63 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 64 | +var uniform = require( '@stdlib/random/base/uniform' ); |
| 65 | +var cphasef = require( '@stdlib/math/base/special/cphasef' ); |
| 66 | + |
| 67 | +var z; |
| 68 | +var i; |
| 69 | + |
| 70 | +for ( i = 0; i < 100; i++ ) { |
| 71 | + z = new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ); |
| 72 | + console.log( 'arg(%s) = %d', z.toString(), cphasef( z ) ); |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +</section> |
| 77 | + |
| 78 | +<!-- /.examples --> |
| 79 | + |
| 80 | +<!-- C interface documentation. --> |
| 81 | + |
| 82 | +* * * |
| 83 | + |
| 84 | +<section class="c"> |
| 85 | + |
| 86 | +## C APIs |
| 87 | + |
| 88 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 89 | + |
| 90 | +<section class="intro"> |
| 91 | + |
| 92 | +</section> |
| 93 | + |
| 94 | +<!-- /.intro --> |
| 95 | + |
| 96 | +<!-- C usage documentation. --> |
| 97 | + |
| 98 | +<section class="usage"> |
| 99 | + |
| 100 | +### Usage |
| 101 | + |
| 102 | +```c |
| 103 | +#include "stdlib/math/base/special/cphasef.h" |
| 104 | +``` |
| 105 | + |
| 106 | +#### stdlib_base_cphasef( z ) |
| 107 | + |
| 108 | +Computes the [argument][complex-number-argument] of a single-precision complex floating-point number. |
| 109 | + |
| 110 | +```c |
| 111 | +#include "stdlib/complex/float32/ctor.h" |
| 112 | +#include "stdlib/complex/float32/real.h" |
| 113 | +#include "stdlib/complex/float32/imag.h" |
| 114 | + |
| 115 | +stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); |
| 116 | +float out = stdlib_base_cphasef( z ); |
| 117 | +// returns ~0.5404f |
| 118 | +``` |
| 119 | + |
| 120 | +The function accepts the following arguments: |
| 121 | + |
| 122 | +- **z**: `[in] stdlib_complex64_t` input value. |
| 123 | + |
| 124 | +```c |
| 125 | +float stdlib_base_cphasef( const stdlib_complex64_t z ); |
| 126 | +``` |
| 127 | +
|
| 128 | +</section> |
| 129 | +
|
| 130 | +<!-- /.usage --> |
| 131 | +
|
| 132 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 133 | +
|
| 134 | +<section class="notes"> |
| 135 | +
|
| 136 | +</section> |
| 137 | +
|
| 138 | +<!-- /.notes --> |
| 139 | +
|
| 140 | +<!-- C API usage examples. --> |
| 141 | +
|
| 142 | +<section class="examples"> |
| 143 | +
|
| 144 | +### Examples |
| 145 | +
|
| 146 | +```c |
| 147 | +#include "stdlib/math/base/special/cphase.h" |
| 148 | +#include "stdlib/complex/float32/ctor.h" |
| 149 | +#include "stdlib/complex/float32/reim.h" |
| 150 | +#include <stdio.h> |
| 151 | +
|
| 152 | +int main( void ) { |
| 153 | + const stdlib_complex64_t x[] = { |
| 154 | + stdlib_complex64( 3.14f, 1.0f ), |
| 155 | + stdlib_complex64( -3.14f, -1.0f ), |
| 156 | + stdlib_complex64( 0.0f, 0.0f ), |
| 157 | + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) |
| 158 | + }; |
| 159 | +
|
| 160 | + stdlib_complex64_t v; |
| 161 | + float re; |
| 162 | + float im; |
| 163 | + float y; |
| 164 | + int i; |
| 165 | + for ( i = 0; i < 4; i++ ) { |
| 166 | + v = x[ i ]; |
| 167 | + y = stdlib_base_cphasef( v ); |
| 168 | + stdlib_complex64_reim( v, &re, &im ); |
| 169 | + printf( "fcphasef(%f + %lfi) = %f\n", re, im, y ); |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +</section> |
| 175 | + |
| 176 | +<!-- /.examples --> |
| 177 | + |
| 178 | +</section> |
| 179 | + |
| 180 | +<!-- /.c --> |
| 181 | + |
| 182 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 183 | + |
| 184 | +<section class="related"> |
| 185 | + |
| 186 | +</section> |
| 187 | + |
| 188 | +<!-- /.related --> |
| 189 | + |
| 190 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 191 | + |
| 192 | +<section class="links"> |
| 193 | + |
| 194 | +[complex-number-argument]: https://en.wikipedia.org/wiki/Argument_%28complex_analysis%29 |
| 195 | + |
| 196 | +<!-- <related-links> --> |
| 197 | + |
| 198 | +<!-- </related-links> --> |
| 199 | + |
| 200 | +</section> |
| 201 | + |
| 202 | +<!-- /.links --> |
0 commit comments