|
| 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 | +# ldexpf |
| 22 | + |
| 23 | +> Multiply a [single-precision floating-point number][ieee754] by an integer power of two. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var ldexpf = require( '@stdlib/math/base/special/ldexpf' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### ldexpf( frac, exp ) |
| 34 | + |
| 35 | +Multiplies a [single-precision floating-point number][ieee754] by an `integer` power of two (i.e., `x = frac * 2^exp`). |
| 36 | + |
| 37 | +```javascript |
| 38 | +var x = ldexpf( 0.5, 3 ); // => 0.5 * 2^3 = 0.5 * 8 |
| 39 | +// returns 4.0 |
| 40 | + |
| 41 | +x = ldexpf( 4.0, -2 ); // => 4 * 2^(-2) = 4 * (1/4) |
| 42 | +// returns 1.0 |
| 43 | +``` |
| 44 | + |
| 45 | +If `frac` equals positive or negative zero, `NaN`, or positive or negative `infinity`, the function returns a value equal to `frac`. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var x = ldexpf( 0.0, 20 ); |
| 49 | +// returns 0.0 |
| 50 | + |
| 51 | +x = ldexpf( -0.0, 39 ); |
| 52 | +// returns -0.0 |
| 53 | + |
| 54 | +x = ldexpf( NaN, -101 ); |
| 55 | +// returns NaN |
| 56 | + |
| 57 | +x = ldexpf( Infinity, 11 ); |
| 58 | +// returns Infinity |
| 59 | + |
| 60 | +x = ldexpf( -Infinity, -118 ); |
| 61 | +// returns -Infinity |
| 62 | +``` |
| 63 | + |
| 64 | +<section class="usage"> |
| 65 | + |
| 66 | +<section class="notes"> |
| 67 | + |
| 68 | +## Notes |
| 69 | + |
| 70 | +// TODO: update this once we have `frexpf`. |
| 71 | + |
| 72 | +- This function is the inverse of [`frexp`][@stdlib/math/base/special/frexp]. |
| 73 | + |
| 74 | +</section> |
| 75 | + |
| 76 | +<!-- /.notes --> |
| 77 | + |
| 78 | +<section class="examples"> |
| 79 | + |
| 80 | +## Examples |
| 81 | + |
| 82 | +<!-- eslint no-undef: "error" --> |
| 83 | + |
| 84 | +```javascript |
| 85 | +var linspace = require( '@stdlib/array/base/linspace' ); |
| 86 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 87 | +var ldexpf = require( '@stdlib/math/base/special/ldexpf' ); |
| 88 | + |
| 89 | +var frac = linspace( 0.0, 100.0, 10 ); |
| 90 | +var exp = discreteUniform( 100, 0, 10 ); |
| 91 | + |
| 92 | +var i; |
| 93 | +for ( i = 0; i < frac.length; i++ ) { |
| 94 | + console.log( 'ldexpf(%d,%d) = %d', frac[ i ], exp[ i ], ldexpf( frac[ i ], exp[ i ] ) ); |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +</section> |
| 99 | + |
| 100 | +<!-- /.examples --> |
| 101 | + |
| 102 | +<!-- C interface documentation. --> |
| 103 | + |
| 104 | +* * * |
| 105 | + |
| 106 | +<section class="c"> |
| 107 | + |
| 108 | +## C APIs |
| 109 | + |
| 110 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 111 | + |
| 112 | +<section class="intro"> |
| 113 | + |
| 114 | +</section> |
| 115 | + |
| 116 | +<!-- /.intro --> |
| 117 | + |
| 118 | +<!-- C usage documentation. --> |
| 119 | + |
| 120 | +<section class="usage"> |
| 121 | + |
| 122 | +### Usage |
| 123 | + |
| 124 | +```c |
| 125 | +#include "stdlib/math/base/special/ldexpf.h" |
| 126 | +``` |
| 127 | + |
| 128 | +#### stdlib_base_ldexpf( frac, exp ) |
| 129 | + |
| 130 | +Multiplies a [single-precision floating-point number][ieee754] by an integer power of two (i.e., `x = frac * 2^exp`). |
| 131 | + |
| 132 | +```c |
| 133 | +float x = stdlib_base_ldexpf( 0.5f, 3 ); // => 0.5 * 2^3 = 0.5 * 8 |
| 134 | +// returns 4.0f |
| 135 | +``` |
| 136 | + |
| 137 | +The function accepts the following arguments: |
| 138 | + |
| 139 | +- **frac**: `[in] float` input value. |
| 140 | +- **exp**: `[in] int32_t` integer power of two. |
| 141 | + |
| 142 | +```c |
| 143 | +float stdlib_base_ldexpf( const float frac, const int32_t exp ); |
| 144 | +``` |
| 145 | +
|
| 146 | +</section> |
| 147 | +
|
| 148 | +<!-- /.usage --> |
| 149 | +
|
| 150 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 151 | +
|
| 152 | +<section class="notes"> |
| 153 | +
|
| 154 | +</section> |
| 155 | +
|
| 156 | +<!-- /.notes --> |
| 157 | +
|
| 158 | +<!-- C API usage examples. --> |
| 159 | +
|
| 160 | +<section class="examples"> |
| 161 | +
|
| 162 | +### Examples |
| 163 | +
|
| 164 | +```c |
| 165 | +#include "stdlib/math/base/special/ldexpf.h" |
| 166 | +#include <stdint.h> |
| 167 | +#include <stdio.h> |
| 168 | +
|
| 169 | +int main( void ) { |
| 170 | + float y; |
| 171 | + int i; |
| 172 | +
|
| 173 | + const float frac[] = { 0.5f, 5.0f, 0.0f, 3.5f, 7.9f }; |
| 174 | + const int32_t exp[] = { 3, -2, 20, 39, 14 }; |
| 175 | +
|
| 176 | + for ( i = 0; i < 5; i++ ) { |
| 177 | + y = stdlib_base_ldexpf( frac[ i ], exp[ i ] ); |
| 178 | + printf( "ldexpf(%f, %d) = %f\n", frac[ i ], exp[ i ], y ); |
| 179 | + } |
| 180 | +} |
| 181 | +``` |
| 182 | + |
| 183 | +</section> |
| 184 | + |
| 185 | +<!-- /.examples --> |
| 186 | + |
| 187 | +</section> |
| 188 | + |
| 189 | +<!-- /.c --> |
| 190 | + |
| 191 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 192 | + |
| 193 | +<section class="related"> |
| 194 | + |
| 195 | +</section> |
| 196 | + |
| 197 | +<!-- /.related --> |
| 198 | + |
| 199 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 200 | + |
| 201 | +<section class="links"> |
| 202 | + |
| 203 | +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 |
| 204 | +[@stdlib/math/base/special/frexp]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/frexp |
| 205 | + |
| 206 | +<!-- <related-links> --> |
| 207 | + |
| 208 | +<!-- </related-links> --> |
| 209 | + |
| 210 | +</section> |
| 211 | + |
| 212 | +<!-- /.links --> |
0 commit comments