README.md (3074B)
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 # wrap 22 23 > Wrap a value on the half-open interval `[min,max)`. 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 wrap = require( '@stdlib/math/base/special/wrap' ); 41 ``` 42 43 #### wrap( v, min, max ) 44 45 Wraps a value on the half-open interval `[min,max)`. 46 47 ```javascript 48 var v = wrap( 3.14, 0.0, 5.0 ); 49 // returns 3.14 50 51 v = wrap( -3.14, 0.0, 5.0 ); 52 // returns ~1.86 53 54 v = wrap( 10.0, 0.0, 5.0 ); 55 // returns 0.0 56 57 v = wrap( -0.0, 0.0, 5.0 ); 58 // returns 0.0 59 60 v = wrap( 0.0, -3.14, -0.0 ); 61 // returns -3.14 62 ``` 63 64 If provided `NaN` for any argument, the function returns `NaN`. 65 66 ```javascript 67 var v = wrap( NaN, 0.0, 5.0 ); 68 // returns NaN 69 70 v = wrap( 0.0, NaN, 5.0 ); 71 // returns NaN 72 73 v = wrap( 3.14, 0.0, NaN ); 74 // returns NaN 75 ``` 76 77 If provided `min == max`, the function returns `NaN`. 78 79 ```javascript 80 var v = wrap( 3.14, 3.0, 3.0 ); 81 // returns NaN 82 ``` 83 84 </section> 85 86 <!-- /.usage --> 87 88 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 89 90 <section class="notes"> 91 92 ## Notes 93 94 - The function does **not** distinguish between positive and negative zero. Where appropriate, the function returns positive zero. 95 96 </section> 97 98 <!-- /.notes --> 99 100 <!-- Package usage examples. --> 101 102 <section class="examples"> 103 104 ## Examples 105 106 <!-- eslint no-undef: "error" --> 107 108 ```javascript 109 var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); 110 var wrap = require( '@stdlib/math/base/special/wrap' ); 111 112 var min; 113 var max; 114 var v; 115 var i; 116 117 for ( i = 0; i < 100; i++ ) { 118 min = discreteUniform( 0.0, 10.0 ); 119 max = discreteUniform( 5.0, 15.0 ); 120 v = discreteUniform( -20.0, 20.0 ); 121 console.log( 'wrap(%d,%d,%d) => %d', v, min, max, wrap( v, min, max ) ); 122 } 123 ``` 124 125 </section> 126 127 <!-- /.examples --> 128 129 <!-- 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. --> 130 131 <section class="references"> 132 133 </section> 134 135 <!-- /.references --> 136 137 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 138 139 <section class="links"> 140 141 </section> 142 143 <!-- /.links -->