README.md (1849B)
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 # round2 22 23 > Round a numeric value to the nearest power of two on a linear scale. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var round2 = require( '@stdlib/math/base/special/round2' ); 31 ``` 32 33 #### round2( x ) 34 35 Rounds a `numeric` value to the nearest power of two on a linear scale. 36 37 ```javascript 38 var v = round2( -4.2 ); 39 // returns -4.0 40 41 v = round2( -4.5 ); 42 // returns -4.0 43 44 v = round2( -4.6 ); 45 // returns -4.0 46 47 v = round2( 9.99999 ); 48 // returns 8.0 49 50 v = round2( 9.5 ); 51 // returns 8.0 52 53 v = round2( 13.0 ); 54 // returns 16.0 55 56 v = round2( -13.0 ); 57 // returns -16.0 58 59 v = round2( 0.0 ); 60 // returns 0.0 61 62 v = round2( -0.0 ); 63 // returns -0.0 64 65 v = round2( Infinity ); 66 // returns Infinity 67 68 v = round2( -Infinity ); 69 // returns -Infinity 70 71 v = round2( NaN ); 72 // returns NaN 73 ``` 74 75 </section> 76 77 <!-- /.usage --> 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 round2 = require( '@stdlib/math/base/special/round2' ); 88 89 var x; 90 var v; 91 var i; 92 93 for ( i = 0; i < 100; i++ ) { 94 x = (randu()*100.0) - 50.0; 95 v = round2( x ); 96 console.log( 'Value: %d. Rounded: %d.', x, v ); 97 } 98 ``` 99 100 </section> 101 102 <!-- /.examples --> 103 104 <section class="links"> 105 106 </section> 107 108 <!-- /.links -->