|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# ceil2f |
| 22 | + |
| 23 | +> Round a numeric value to the nearest power of two toward positive infinity. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var ceil2f = require( '@stdlib/math/base/special/ceil2' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### ceil2f( x ) |
| 34 | + |
| 35 | +Rounds a `numeric` value to the nearest power of two toward positive infinity. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var v = ceil2f( -4.2 ); |
| 39 | +// returns -4.0 |
| 40 | + |
| 41 | +v = ceil2f( -4.5 ); |
| 42 | +// returns -4.0 |
| 43 | + |
| 44 | +v = ceil2f( -4.6 ); |
| 45 | +// returns -4.0 |
| 46 | + |
| 47 | +v = ceil2f( 9.99999 ); |
| 48 | +// returns 16.0 |
| 49 | + |
| 50 | +v = ceil2f( 9.5 ); |
| 51 | +// returns 16.0 |
| 52 | + |
| 53 | +v = ceil2f( 13.0 ); |
| 54 | +// returns 16.0 |
| 55 | + |
| 56 | +v = ceil2f( -13.0 ); |
| 57 | +// returns -8.0 |
| 58 | + |
| 59 | +v = ceil2f( 0.0 ); |
| 60 | +// returns 0.0 |
| 61 | + |
| 62 | +v = ceil2f( -0.0 ); |
| 63 | +// returns -0.0 |
| 64 | + |
| 65 | +v = ceil2f( Infinity ); |
| 66 | +// returns Infinity |
| 67 | + |
| 68 | +v = ceil2f( -Infinity ); |
| 69 | +// returns -Infinity |
| 70 | + |
| 71 | +v = ceil2f( 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 ceil2f = require( './../lib' ); |
| 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 = ceil2f( x ); |
| 96 | + console.log( 'x: %d. Rounded: %d.', x, v ); |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +</section> |
| 101 | + |
| 102 | +<!-- /.examples --> |
| 103 | + |
| 104 | +<!-- C interface documentation. --> |
| 105 | + |
| 106 | +* * * |
| 107 | + |
| 108 | +<section class="c"> |
| 109 | + |
| 110 | +## C APIs |
| 111 | + |
| 112 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 113 | + |
| 114 | +<section class="intro"> |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.intro --> |
| 119 | + |
| 120 | +<!-- C usage documentation. --> |
| 121 | + |
| 122 | +<section class="usage"> |
| 123 | + |
| 124 | +### Usage |
| 125 | + |
| 126 | +```c |
| 127 | +#include "stdlib/math/base/special/ceil2f.h" |
| 128 | +``` |
| 129 | + |
| 130 | +#### stdlib_base_ceil2f( x ) |
| 131 | + |
| 132 | +Rounds a `numeric` value to the nearest power of two toward positive infinity. |
| 133 | + |
| 134 | +```c |
| 135 | +double y = stdlib_base_ceil2f( 3.14f ); |
| 136 | +// returns 4.0f |
| 137 | +``` |
| 138 | + |
| 139 | +The function accepts the following arguments: |
| 140 | + |
| 141 | +- **x**: `[in] float` input value. |
| 142 | + |
| 143 | +```c |
| 144 | +float stdlib_base_ceil2f( const float x ); |
| 145 | +``` |
| 146 | +
|
| 147 | +</section> |
| 148 | +
|
| 149 | +<!-- /.usage --> |
| 150 | +
|
| 151 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 152 | +
|
| 153 | +<section class="notes"> |
| 154 | +
|
| 155 | +</section> |
| 156 | +
|
| 157 | +<!-- /.notes --> |
| 158 | +
|
| 159 | +<!-- C API usage examples. --> |
| 160 | +
|
| 161 | +<section class="examples"> |
| 162 | +
|
| 163 | +### Examples |
| 164 | +
|
| 165 | +```c |
| 166 | +#include "stdlib/math/base/special/ceil2f.h" |
| 167 | +#include <stdio.h> |
| 168 | +
|
| 169 | +int main( void ) { |
| 170 | + const float x[] = { 3.14f, -3.14f, 0.5f, 0.0 / 0.0 }; |
| 171 | +
|
| 172 | + float y; |
| 173 | + int i; |
| 174 | + for ( i = 0; i < 4; i++ ) { |
| 175 | + y = stdlib_base_ceil2f( x[ i ] ); |
| 176 | + printf( "ceil2f(%f) = %f\n", x[ i ], y ); |
| 177 | + } |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +</section> |
| 182 | + |
| 183 | +<!-- /.examples --> |
| 184 | + |
| 185 | +</section> |
| 186 | + |
| 187 | +<!-- /.c --> |
| 188 | + |
| 189 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 190 | + |
| 191 | +<section class="related"> |
| 192 | + |
| 193 | +* * * |
| 194 | + |
| 195 | +## See Also |
| 196 | + |
| 197 | +- <span class="package-name">[`@stdlib/math/base/special/ceil`][@stdlib/math/base/special/ceil]</span><span class="delimiter">: </span><span class="description">round a double-precision floating-point number toward positive infinity.</span> |
| 198 | +- <span class="package-name">[`@stdlib/math/base/special/ceil10`][@stdlib/math/base/special/ceil10]</span><span class="delimiter">: </span><span class="description">round a numeric value to the nearest power of 10 toward positive infinity.</span> |
| 199 | +- <span class="package-name">[`@stdlib/math/base/special/floor2`][@stdlib/math/base/special/floor2]</span><span class="delimiter">: </span><span class="description">round a numeric value to the nearest power of two toward negative infinity.</span> |
| 200 | +- <span class="package-name">[`@stdlib/math/base/special/round2`][@stdlib/math/base/special/round2]</span><span class="delimiter">: </span><span class="description">round a numeric value to the nearest power of two on a linear scale.</span> |
| 201 | + |
| 202 | +</section> |
| 203 | + |
| 204 | +<!-- /.related --> |
| 205 | + |
| 206 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 207 | + |
| 208 | +<section class="links"> |
| 209 | + |
| 210 | +<!-- <related-links> --> |
| 211 | + |
| 212 | +[@stdlib/math/base/special/ceil]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/ceil |
| 213 | + |
| 214 | +[@stdlib/math/base/special/ceil10]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/ceil10 |
| 215 | + |
| 216 | +[@stdlib/math/base/special/floor2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/floor2 |
| 217 | + |
| 218 | +[@stdlib/math/base/special/round2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/round2 |
| 219 | + |
| 220 | +<!-- </related-links> --> |
| 221 | + |
| 222 | +</section> |
| 223 | + |
| 224 | +<!-- /.links --> |
0 commit comments