|
| 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 70 | +var sqrtpif = require( '@stdlib/math/base/special/sqrtpif' ); |
| 71 | + |
| 72 | +var x; |
| 73 | +var i; |
| 74 | + |
| 75 | +for ( i = 0; i < 100; i++ ) { |
| 76 | + x = discreteUniform( 0, 100 ); |
| 77 | + console.log( 'sqrtpif(%d) = %d', x, sqrtpif( x ) ); |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +</section> |
| 82 | + |
| 83 | +<!-- /.examples --> |
| 84 | + |
| 85 | +<!-- C interface documentation. --> |
| 86 | + |
| 87 | +* * * |
| 88 | + |
| 89 | +<section class="c"> |
| 90 | + |
| 91 | +## C APIs |
| 92 | + |
| 93 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 94 | + |
| 95 | +<section class="intro"> |
| 96 | + |
| 97 | +</section> |
| 98 | + |
| 99 | +<!-- /.intro --> |
| 100 | + |
| 101 | +<!-- C usage documentation. --> |
| 102 | + |
| 103 | +<section class="usage"> |
| 104 | + |
| 105 | +### Usage |
| 106 | + |
| 107 | +```c |
| 108 | +#include "stdlib/math/base/special/sqrtpif.h" |
| 109 | +``` |
| 110 | + |
| 111 | +#### stdlib_base_sqrtpif( x ) |
| 112 | + |
| 113 | +Computes the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number. |
| 114 | + |
| 115 | +```c |
| 116 | +float x = stdlib_base_sqrtpif( 4.0 ); |
| 117 | +// returns ~3.5449 |
| 118 | + |
| 119 | +x = stdlib_base_sqrtpif( 10.0 ); |
| 120 | +// returns ~5.60499 |
| 121 | +``` |
| 122 | + |
| 123 | +The function accepts the following arguments: |
| 124 | + |
| 125 | +- **x**: `[in] float` input value. |
| 126 | + |
| 127 | +```c |
| 128 | +float stdlib_base_sqrtpif( const float x ); |
| 129 | +``` |
| 130 | +
|
| 131 | +</section> |
| 132 | +
|
| 133 | +<!-- /.usage --> |
| 134 | +
|
| 135 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 136 | +
|
| 137 | +<section class="notes"> |
| 138 | +
|
| 139 | +</section> |
| 140 | +
|
| 141 | +<!-- /.notes --> |
| 142 | +
|
| 143 | +<!-- C API usage examples. --> |
| 144 | +
|
| 145 | +<section class="examples"> |
| 146 | +
|
| 147 | +### Examples |
| 148 | +
|
| 149 | +```c |
| 150 | +#include "stdlib/math/base/special/sqrtpif.h" |
| 151 | +#include <stdlib.h> |
| 152 | +#include <stdio.h> |
| 153 | +
|
| 154 | +int main( void ) { |
| 155 | + float x; |
| 156 | + float v; |
| 157 | + int i; |
| 158 | +
|
| 159 | + for ( i = 0; i < 100; i++ ) { |
| 160 | + x = ( (float)rand() / (float)RAND_MAX ) * 100.0; |
| 161 | + v = stdlib_base_sqrtpif( x ); |
| 162 | + printf( "sqrtpif(%f) = %f\n", x, v ); |
| 163 | + } |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +</section> |
| 168 | + |
| 169 | +<!-- /.examples --> |
| 170 | + |
| 171 | +</section> |
| 172 | + |
| 173 | +<!-- /.c --> |
| 174 | + |
| 175 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 176 | + |
| 177 | +<section class="related"> |
| 178 | + |
| 179 | +* * * |
| 180 | + |
| 181 | +## See Also |
| 182 | + |
| 183 | +- <span class="package-name">[`@stdlib/math/base/special/sqrt`][@stdlib/math/base/special/sqrt]</span><span class="delimiter">: </span><span class="description">compute the principal square root of a double-precision floating-point number.</span> |
| 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 | +[@stdlib/math/base/special/sqrt]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sqrt |
| 194 | + |
| 195 | +<!-- <related-links> --> |
| 196 | + |
| 197 | +<!-- </related-links> --> |
| 198 | + |
| 199 | +</section> |
| 200 | + |
| 201 | +<!-- /.links --> |
0 commit comments