README.md (4041B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # Alpha Max Plus Beta Min 22 23 > Compute the [hypotenuse][hypotenuse] using the [alpha max plus beta min algorithm][alpha-max-plus-beta-min]. 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 ampbm = require( '@stdlib/math/base/special/fast/alpha-max-plus-beta-min' ); 41 ``` 42 43 #### ampbm( x, y ) 44 45 Computes the [hypotenuse][hypotenuse] using the [alpha max plus beta min algorithm][alpha-max-plus-beta-min]. 46 47 ```javascript 48 var h = ampbm( -5.0, 12.0 ); 49 // returns ~13.5 50 ``` 51 52 #### ampbm.factory( alpha, beta, \[nonnegative\[, ints]] ) 53 54 Returns a function for computing the [hypotenuse][hypotenuse] using coefficients `alpha` and `beta`. 55 56 ```javascript 57 var hypot = ampbm.factory( 1.0, 0.5 ); 58 59 var h = hypot( -5.0, 12.0 ); 60 // returns 14.5 61 ``` 62 63 If the returned function should only expect nonnegative arguments, set the `nonnegative` argument to `true`. 64 65 ```javascript 66 var hypot = ampbm.factory( 1.0, 0.5, true ); 67 68 var h = hypot( 5.0, 12.0 ); 69 // returns 14.5 70 ``` 71 72 If the returned function should only expect signed 32-bit integers, set the `ints` argument to `true`. 73 74 ```javascript 75 var hypot = ampbm.factory( 1.0, 0.5, false, true ); 76 77 var h = hypot( -5.0, 12.0 ); 78 // returns 14 79 ``` 80 81 If the returned function should only expect unsigned 32-bit integer valued arguments, set the `nonnegative` and `ints` arguments to `true`. 82 83 ```javascript 84 var hypot = ampbm.factory( 1.0, 0.5, true, true ); 85 86 var h = hypot( 5.0, 12.0 ); 87 // returns 14 88 ``` 89 90 </section> 91 92 <!-- /.usage --> 93 94 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 95 96 <section class="notes"> 97 98 ## Notes 99 100 - The algorithm computes only an **approximation**. For precise results, use [`hypot`][@stdlib/math/base/special/hypot]. 101 102 </section> 103 104 <!-- /.notes --> 105 106 <!-- Package usage examples. --> 107 108 <section class="examples"> 109 110 ## Examples 111 112 <!-- eslint no-undef: "error" --> 113 114 ```javascript 115 var randu = require( '@stdlib/random/base/randu' ); 116 var round = require( '@stdlib/math/base/special/round' ); 117 var ampbm = require( '@stdlib/math/base/special/fast/alpha-max-plus-beta-min' ); 118 119 var x; 120 var y; 121 var h; 122 var i; 123 124 for ( i = 0; i < 100; i++ ) { 125 x = round( randu()*100.0 ) - 50.0; 126 y = round( randu()*100.0 ) - 50.0; 127 h = ampbm( x, y ); 128 console.log( 'hypot(%d,%d) = %d', x, y, h ); 129 } 130 ``` 131 132 </section> 133 134 <!-- /.examples --> 135 136 <!-- 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. --> 137 138 <section class="references"> 139 140 ## References 141 142 - Lyons, Richard G. 2011. _Understanding Digital Signal Processing, 3rd Edition_. Prentice Hall. 143 144 </section> 145 146 <!-- /.references --> 147 148 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 149 150 <section class="links"> 151 152 [hypotenuse]: http://en.wikipedia.org/wiki/Pythagorean_theorem 153 154 [alpha-max-plus-beta-min]: https://en.wikipedia.org/wiki/Alpha_max_plus_beta_min_algorithm 155 156 [@stdlib/math/base/special/hypot]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/hypot 157 158 </section> 159 160 <!-- /.links -->