|
| 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 | +# hypotf |
| 22 | + |
| 23 | +> Compute the [hypotenuse][hypotenuse] of a single-precision floating-point number. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var hypotf = require( '@stdlib/math/base/special/fast/hypotf' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### hypotf( x, y ) |
| 44 | + |
| 45 | +Computes the [hypotenuse][hypotenuse] of a single-precision floating-point number. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var h = hypotf( -5.0, 12.0 ); |
| 49 | +// returns 13.0 |
| 50 | +``` |
| 51 | + |
| 52 | +</section> |
| 53 | + |
| 54 | +<!-- /.usage --> |
| 55 | + |
| 56 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 57 | + |
| 58 | +<section class="notes"> |
| 59 | + |
| 60 | +## Notes |
| 61 | + |
| 62 | +- For a sufficiently large `x` and/or `y`, computing the hypotenuse will overflow. |
| 63 | + |
| 64 | + ```javascript |
| 65 | + var h = hypotf( 1.0e154, 1.0e154 ); |
| 66 | + // returns Infinity |
| 67 | + ``` |
| 68 | + |
| 69 | + Similarly, for sufficiently small `x` and/or `y`, computing the hypotenuse will underflow. |
| 70 | + |
| 71 | + ```javascript |
| 72 | + var h = hypotf( 1e-200, 1.0e-200 ); |
| 73 | + // returns 0.0 |
| 74 | + ``` |
| 75 | + |
| 76 | +</section> |
| 77 | + |
| 78 | +<!-- /.notes --> |
| 79 | + |
| 80 | +<!-- Package usage examples. --> |
| 81 | + |
| 82 | +<section class="examples"> |
| 83 | + |
| 84 | +## Examples |
| 85 | + |
| 86 | +<!-- eslint no-undef: "error" --> |
| 87 | + |
| 88 | +```javascript |
| 89 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 90 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 91 | +var hypotf = require( '@stdlib/math/base/special/fast/hypotf' ); |
| 92 | +
|
| 93 | +var opts = { |
| 94 | + 'dtype': 'float32' |
| 95 | +}; |
| 96 | +var x = discreteUniform( 100, -50, 50, opts ); |
| 97 | +var y = discreteUniform( 100, -50, 50, opts ); |
| 98 | +
|
| 99 | +logEachMap( 'h(%d,%d) = %0.4f', x, y, hypotf ); |
| 100 | +``` |
| 101 | + |
| 102 | +</section> |
| 103 | + |
| 104 | +<!-- /.examples --> |
| 105 | + |
| 106 | +<!-- C interface documentation. --> |
| 107 | + |
| 108 | +* * * |
| 109 | + |
| 110 | +<section class="c"> |
| 111 | + |
| 112 | +## C APIs |
| 113 | + |
| 114 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 115 | + |
| 116 | +<section class="intro"> |
| 117 | + |
| 118 | +</section> |
| 119 | + |
| 120 | +<!-- /.intro --> |
| 121 | + |
| 122 | +<!-- C usage documentation. --> |
| 123 | + |
| 124 | +<section class="usage"> |
| 125 | + |
| 126 | +### Usage |
| 127 | + |
| 128 | +```c |
| 129 | +#include "stdlib/math/base/special/fast/hypotf.h" |
| 130 | +``` |
| 131 | + |
| 132 | +#### stdlib_base_fast_hypotf( x, y ) |
| 133 | + |
| 134 | +Computes the hypotenuse of a single-precision floating-point number. |
| 135 | + |
| 136 | +```c |
| 137 | +float h = stdlib_base_fast_hypotf( 5.0f, 12.0f ); |
| 138 | +// returns 13.0f |
| 139 | +``` |
| 140 | + |
| 141 | +The function accepts the following arguments: |
| 142 | + |
| 143 | +- **x**: `[in] float` input value. |
| 144 | +- **y**: `[in] float` input value. |
| 145 | + |
| 146 | +```c |
| 147 | +float stdlib_base_fast_hypotf( const float x, const float y ); |
| 148 | +``` |
| 149 | +
|
| 150 | +</section> |
| 151 | +
|
| 152 | +<!-- /.usage --> |
| 153 | +
|
| 154 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 155 | +
|
| 156 | +<section class="notes"> |
| 157 | +
|
| 158 | +</section> |
| 159 | +
|
| 160 | +<!-- /.notes --> |
| 161 | +
|
| 162 | +<!-- C API usage examples. --> |
| 163 | +
|
| 164 | +<section class="examples"> |
| 165 | +
|
| 166 | +### Examples |
| 167 | +
|
| 168 | +```c |
| 169 | +#include "stdlib/math/base/special/fast/hypotf.h" |
| 170 | +#include <stdio.h> |
| 171 | + |
| 172 | +int main( void ) { |
| 173 | + const float x[] = { 3.0f, 4.0f, 5.0f, 12.0f }; |
| 174 | + |
| 175 | + float y; |
| 176 | + int i; |
| 177 | + for ( i = 0; i < 4; i += 2 ) { |
| 178 | + y = stdlib_base_fast_hypotf( x[ i ], x[ i+1 ] ); |
| 179 | + printf( "hypot(%f, %f) = %f\n", x[ i ], x[ i+1 ], y ); |
| 180 | + } |
| 181 | +} |
| 182 | +``` |
| 183 | +
|
| 184 | +</section> |
| 185 | +
|
| 186 | +<!-- /.examples --> |
| 187 | +
|
| 188 | +</section> |
| 189 | +
|
| 190 | +<!-- /.c --> |
| 191 | +
|
| 192 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 193 | +
|
| 194 | +<section class="references"> |
| 195 | +
|
| 196 | +</section> |
| 197 | +
|
| 198 | +<!-- /.references --> |
| 199 | +
|
| 200 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 201 | +
|
| 202 | +<section class="related"> |
| 203 | +
|
| 204 | +
|
| 205 | +</section> |
| 206 | +
|
| 207 | +<!-- /.related --> |
| 208 | +
|
| 209 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 210 | +
|
| 211 | +<section class="links"> |
| 212 | +
|
| 213 | +[hypotenuse]: https://en.wikipedia.org/wiki/Pythagorean_theorem |
| 214 | +
|
| 215 | +
|
| 216 | +</section> |
| 217 | +
|
| 218 | +<!-- /.links --> |
0 commit comments