README.md (4182B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 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] avoiding overflow and underflow (single-precision). 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/hypotf' ); 41 ``` 42 43 #### hypotf( x, y ) 44 45 Computes the [hypotenuse][hypotenuse] avoiding overflow and underflow (single-precision). 46 47 ```javascript 48 var h = hypotf( -5.0, 12.0 ); 49 // returns 13.0 50 51 h = hypotf( -0.0, -0.0 ); 52 // returns +0.0 53 ``` 54 55 If either argument is `NaN`, the function returns `NaN`. 56 57 ```javascript 58 var h = hypotf( NaN, 12.0 ); 59 // returns NaN 60 61 h = hypotf( 5.0, NaN ); 62 // returns NaN 63 ``` 64 65 </section> 66 67 <!-- /.usage --> 68 69 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 70 71 <section class="notes"> 72 73 </section> 74 75 <!-- /.notes --> 76 77 <!-- Package usage examples. --> 78 79 <section class="examples"> 80 81 ## Examples 82 83 <!-- eslint no-undef: "error" --> 84 85 ```javascript 86 var randu = require( '@stdlib/random/base/randu' ); 87 var round = require( '@stdlib/math/base/special/round' ); 88 var hypotf = require( '@stdlib/math/base/special/hypotf' ); 89 90 var x; 91 var y; 92 var h; 93 var i; 94 95 for ( i = 0; i < 100; i++ ) { 96 x = round( randu()*100.0 ) - 50.0; 97 y = round( randu()*100.0 ) - 50.0; 98 h = hypotf( x, y ); 99 console.log( 'h(%d,%d) = %d', x, y, h ); 100 } 101 ``` 102 103 </section> 104 105 <!-- /.examples --> 106 107 <!-- C interface documentation. --> 108 109 * * * 110 111 <section class="c"> 112 113 ## C APIs 114 115 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 116 117 <section class="intro"> 118 119 </section> 120 121 <!-- /.intro --> 122 123 <!-- C usage documentation. --> 124 125 <section class="usage"> 126 127 ### Usage 128 129 ```c 130 #include "stdlib/math/base/special/hypotf.h 131 ``` 132 133 #### stdlib_base_hypotf( x, y ) 134 135 Computes the hypotenuse avoiding overflow and underflow (single-precision). 136 137 ```c 138 float h = stdlib_base_hypotf( 5.0f, 12.0f ); 139 // returns 13.0f 140 ``` 141 142 The function accepts the following arguments: 143 144 - **x**: `[in] float` input value. 145 - **y**: `[in] float` input value. 146 147 ```c 148 float stdlib_base_hypotf( const float x, const float y ); 149 ``` 150 151 </section> 152 153 <!-- /.usage --> 154 155 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 156 157 <section class="notes"> 158 159 </section> 160 161 <!-- /.notes --> 162 163 <!-- C API usage examples. --> 164 165 <section class="examples"> 166 167 ### Examples 168 169 ```c 170 #include "stdlib/math/base/special/hypotf.h" 171 #include <stdio.h> 172 173 int main() { 174 float x[] = { 3.0f, 4.0f, 5.0f, 12.0f }; 175 176 float y; 177 int i; 178 for ( i = 0; i < 4; i += 2 ) { 179 y = stdlib_base_hypotf( x[ i ], x[ i+1 ] ); 180 printf( "hypot(%f, %f) = %f\n", x[ i ], x[ i+1 ], y ); 181 } 182 } 183 ``` 184 185 </section> 186 187 <!-- /.examples --> 188 189 </section> 190 191 <!-- /.c --> 192 193 <!-- 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. --> 194 195 <section class="references"> 196 197 </section> 198 199 <!-- /.references --> 200 201 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 202 203 <section class="links"> 204 205 [hypotenuse]: http://en.wikipedia.org/wiki/Pythagorean_theorem 206 207 </section> 208 209 <!-- /.links -->