|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# sqrtpif |
| 22 | + |
| 23 | +> Compute the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var sqrtpif = require( '@stdlib/math/base/special/sqrtpif' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### sqrtpif( x ) |
| 34 | + |
| 35 | +Computes the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var v = sqrtpif( 4.0 ); |
| 39 | +// returns ~3.5449 |
| 40 | + |
| 41 | +v = sqrtpif( 10.0 ); |
| 42 | +// returns ~5.60499 |
| 43 | + |
| 44 | +v = sqrtpif( 0.0 ); |
| 45 | +// returns 0.0 |
| 46 | + |
| 47 | +v = sqrtpif( NaN ); |
| 48 | +// returns NaN |
| 49 | +``` |
| 50 | + |
| 51 | +For negative numbers, the principal [square root][@stdlib/math/base/special/sqrt] is **not** defined. |
| 52 | + |
| 53 | +```javascript |
| 54 | +var v = sqrtpif( -4.0 ); |
| 55 | +// returns NaN |
| 56 | +``` |
| 57 | + |
| 58 | +</section> |
| 59 | + |
| 60 | +<!-- /.usage --> |
| 61 | + |
| 62 | +<section class="examples"> |
| 63 | + |
| 64 | +## Examples |
| 65 | + |
| 66 | +<!-- eslint no-undef: "error" --> |
| 67 | + |
| 68 | +```javascript |
| 69 | +var randu = require( '@stdlib/random/array/discrete-uniform' ); |
| 70 | +var sqrtpif = require( '@stdlib/math/base/special/sqrtpif' ); |
| 71 | + |
| 72 | +var x = randu( 100, 0.0, 100.0 ); |
| 73 | + |
| 74 | +var i; |
| 75 | +for ( i = 0; i < 100; i++ ) { |
| 76 | + console.log( 'sqrtpif(%d) = %d', x[ i ], sqrtpif( x[ i ] ) ); |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +</section> |
| 81 | + |
| 82 | +<!-- /.examples --> |
| 83 | + |
| 84 | +<!-- C interface documentation. --> |
| 85 | + |
| 86 | +* * * |
| 87 | + |
| 88 | +<section class="c"> |
| 89 | + |
| 90 | +## C APIs |
| 91 | + |
| 92 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 93 | + |
| 94 | +<section class="intro"> |
| 95 | + |
| 96 | +</section> |
| 97 | + |
| 98 | +<!-- /.intro --> |
| 99 | + |
| 100 | +<!-- C usage documentation. --> |
| 101 | + |
| 102 | +<section class="usage"> |
| 103 | + |
| 104 | +### Usage |
| 105 | + |
| 106 | +```c |
| 107 | +#include "stdlib/math/base/special/sqrtpif.h" |
| 108 | +``` |
| 109 | + |
| 110 | +#### stdlib_base_sqrtpif( x ) |
| 111 | + |
| 112 | +Computes the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number. |
| 113 | + |
| 114 | +```c |
| 115 | +float x = stdlib_base_sqrtpif( 4.0f ); |
| 116 | +// returns ~3.5449f |
| 117 | + |
| 118 | +x = stdlib_base_sqrtpif( 10.0f ); |
| 119 | +// returns ~5.60499f |
| 120 | +``` |
| 121 | + |
| 122 | +The function accepts the following arguments: |
| 123 | + |
| 124 | +- **x**: `[in] float` input value. |
| 125 | + |
| 126 | +```c |
| 127 | +float stdlib_base_sqrtpif( const float x ); |
| 128 | +``` |
| 129 | +
|
| 130 | +</section> |
| 131 | +
|
| 132 | +<!-- /.usage --> |
| 133 | +
|
| 134 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 135 | +
|
| 136 | +<section class="notes"> |
| 137 | +
|
| 138 | +</section> |
| 139 | +
|
| 140 | +<!-- /.notes --> |
| 141 | +
|
| 142 | +<!-- C API usage examples. --> |
| 143 | +
|
| 144 | +<section class="examples"> |
| 145 | +
|
| 146 | +### Examples |
| 147 | +
|
| 148 | +```c |
| 149 | +#include "stdlib/math/base/special/sqrtpif.h" |
| 150 | +#include <stdlib.h> |
| 151 | +#include <stdio.h> |
| 152 | +
|
| 153 | +int main( void ) { |
| 154 | + const float x[] = { 4.0f, 10.0f, 3.14f, -3.14f, 0.0f, 0.0f / 0.0f }; |
| 155 | +
|
| 156 | + float v; |
| 157 | + int i; |
| 158 | + for ( i = 0; i < 6; i++ ) { |
| 159 | + v = stdlib_base_sqrtpif( x[ i ] ); |
| 160 | + printf( "sqrtpif(%f) = %f", x[ i ], v ); |
| 161 | + } |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.examples --> |
| 168 | + |
| 169 | +</section> |
| 170 | + |
| 171 | +<!-- /.c --> |
| 172 | + |
| 173 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 174 | + |
| 175 | +<section class="related"> |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.related --> |
| 180 | + |
| 181 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 182 | + |
| 183 | +<section class="links"> |
| 184 | + |
| 185 | +<!-- <related-links> --> |
| 186 | + |
| 187 | +[@stdlib/math/base/special/sqrt]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sqrt |
| 188 | + |
| 189 | +<!-- </related-links> --> |
| 190 | + |
| 191 | +</section> |
| 192 | + |
| 193 | +<!-- /.links --> |
0 commit comments