|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); |
| 64 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 65 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 66 | +var cphasef = require( '@stdlib/math/base/special/cphasef' ); |
| 67 | + |
| 68 | +// Create an array of random numbers: |
| 69 | +var arr = new Complex64Array( uniform( 200, -100.0, 100.0 ) ); |
| 70 | + |
| 71 | +// Compute the inverse of each number in the array: |
| 72 | +logEachMap( 'cphasef(%s) = %0.4f', arr, cphasef ); |
| 73 | +``` |
| 74 | + |
| 75 | +</section> |
| 76 | + |
| 77 | +<!-- /.examples --> |
| 78 | + |
| 79 | +<!-- C interface documentation. --> |
| 80 | + |
| 81 | +* * * |
| 82 | + |
| 83 | +<section class="c"> |
| 84 | + |
| 85 | +## C APIs |
| 86 | + |
| 87 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 88 | + |
| 89 | +<section class="intro"> |
| 90 | + |
| 91 | +</section> |
| 92 | + |
| 93 | +<!-- /.intro --> |
| 94 | + |
| 95 | +<!-- C usage documentation. --> |
| 96 | + |
| 97 | +<section class="usage"> |
| 98 | + |
| 99 | +### Usage |
| 100 | + |
| 101 | +```c |
| 102 | +#include "stdlib/math/base/special/cphasef.h" |
| 103 | +``` |
| 104 | + |
| 105 | +#### stdlib_base_cphasef( z ) |
| 106 | + |
| 107 | +Computes the [argument][complex-number-argument] of a single-precision complex floating-point number. |
| 108 | + |
| 109 | +```c |
| 110 | +#include "stdlib/complex/float32/ctor.h" |
| 111 | +#include "stdlib/complex/float32/real.h" |
| 112 | +#include "stdlib/complex/float32/imag.h" |
| 113 | + |
| 114 | +stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); |
| 115 | +float out = stdlib_base_cphasef( z ); |
| 116 | +// returns ~0.5404f |
| 117 | +``` |
| 118 | + |
| 119 | +The function accepts the following arguments: |
| 120 | + |
| 121 | +- **z**: `[in] stdlib_complex64_t` input value. |
| 122 | + |
| 123 | +```c |
| 124 | +float stdlib_base_cphasef( const stdlib_complex64_t z ); |
| 125 | +``` |
| 126 | +
|
| 127 | +</section> |
| 128 | +
|
| 129 | +<!-- /.usage --> |
| 130 | +
|
| 131 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 132 | +
|
| 133 | +<section class="notes"> |
| 134 | +
|
| 135 | +</section> |
| 136 | +
|
| 137 | +<!-- /.notes --> |
| 138 | +
|
| 139 | +<!-- C API usage examples. --> |
| 140 | +
|
| 141 | +<section class="examples"> |
| 142 | +
|
| 143 | +### Examples |
| 144 | +
|
| 145 | +```c |
| 146 | +#include "stdlib/math/base/special/cphasef.h" |
| 147 | +#include "stdlib/complex/float32/ctor.h" |
| 148 | +#include "stdlib/complex/float32/reim.h" |
| 149 | +#include <stdio.h> |
| 150 | +
|
| 151 | +int main( void ) { |
| 152 | + const stdlib_complex64_t x[] = { |
| 153 | + stdlib_complex64( 3.14f, 1.0f ), |
| 154 | + stdlib_complex64( -3.14f, -1.0f ), |
| 155 | + stdlib_complex64( 0.0f, 0.0f ), |
| 156 | + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) |
| 157 | + }; |
| 158 | +
|
| 159 | + stdlib_complex64_t v; |
| 160 | + float re; |
| 161 | + float im; |
| 162 | + float y; |
| 163 | + int i; |
| 164 | + for ( i = 0; i < 4; i++ ) { |
| 165 | + v = x[ i ]; |
| 166 | + y = stdlib_base_cphasef( v ); |
| 167 | + stdlib_complex64_reim( v, &re, &im ); |
| 168 | + printf( "cphasef(%f + %fi) = %f\n", re, im, y ); |
| 169 | + } |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +</section> |
| 174 | + |
| 175 | +<!-- /.examples --> |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.c --> |
| 180 | + |
| 181 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 182 | + |
| 183 | +<section class="related"> |
| 184 | + |
| 185 | +</section> |
| 186 | + |
| 187 | +<!-- /.related --> |
| 188 | + |
| 189 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 190 | + |
| 191 | +<section class="links"> |
| 192 | + |
| 193 | +[complex-number-argument]: https://en.wikipedia.org/wiki/Argument_%28complex_analysis%29 |
| 194 | + |
| 195 | +<!-- <related-links> --> |
| 196 | + |
| 197 | +<!-- </related-links> --> |
| 198 | + |
| 199 | +</section> |
| 200 | + |
| 201 | +<!-- /.links --> |
0 commit comments