Skip to content

Commit 19972b4

Browse files
committed
feat: add math/base/special/frexpf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c415ac2 commit 19972b4

File tree

36 files changed

+508
-928
lines changed

36 files changed

+508
-928
lines changed

lib/node_modules/@stdlib/math/base/special/frexpf/README.md

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ limitations under the License.
1818
1919
-->
2020

21-
# frexp
21+
# frexpf
2222

23-
> Split a [double-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
23+
> Split a [single-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
2424
2525
<section class="usage">
2626

2727
## Usage
2828

2929
```javascript
30-
var frexp = require( '@stdlib/math/base/special/frexp' );
30+
var frexpf = require( '@stdlib/math/base/special/frexpf' );
3131
```
3232

33-
#### frexp( x )
33+
#### frexpf( x )
3434

35-
Splits a [double-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
35+
Splits a [single-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
3636

3737
```javascript
38-
var out = frexp( 4.0 );
38+
var out = frexpf( 4.0 );
3939
// returns [ 0.5, 3 ]
4040
```
4141

@@ -45,7 +45,7 @@ By default, the function returns the normalized fraction and the exponent as a t
4545
var pow = require( '@stdlib/math/base/special/pow' );
4646

4747
var x = 4.0;
48-
var out = frexp( x );
48+
var out = frexpf( x );
4949
// returns [ 0.5, 3 ]
5050

5151
var frac = out[ 0 ];
@@ -58,35 +58,35 @@ var bool = ( x === frac * pow(2.0, exp) );
5858
If provided positive or negative zero, `NaN`, or positive or negative `infinity`, the function returns a two-element `array` containing the input value and an exponent equal to `0`.
5959

6060
```javascript
61-
var out = frexp( 0.0 );
61+
var out = frexpf( 0.0 );
6262
// returns [ 0.0, 0 ]
6363

64-
out = frexp( -0.0 );
64+
out = frexpf( -0.0 );
6565
// returns [ -0.0, 0 ]
6666

67-
out = frexp( NaN );
67+
out = frexpf( NaN );
6868
// returns [ NaN, 0 ]
6969

70-
out = frexp( Infinity );
70+
out = frexpf( Infinity );
7171
// returns [ Infinity, 0 ]
7272

73-
out = frexp( -Infinity );
73+
out = frexpf( -Infinity );
7474
// returns [ -Infinity, 0 ]
7575
```
7676

77-
For all other numeric input values, the [absolute value][@stdlib/math/base/special/abs] of the normalized fraction resides on the interval `[0.5,1)`.
77+
For all other numeric input values, the [absolute value][@stdlib/math/base/special/absf] of the normalized fraction resides on the interval `[0.5,1)`.
7878

79-
#### frexp.assign( x, out, stride, offset )
79+
#### frexpf.assign( x, out, stride, offset )
8080

81-
Splits a [double-precision floating-point number][ieee754] into a normalized fraction and an integer power of two and assigns results to a provided output array.
81+
Splits a [single-precision floating-point number][ieee754] into a normalized fraction and an integer power of two and assigns results to a provided output array.
8282

8383
```javascript
84-
var Float64Array = require( '@stdlib/array/float64' );
84+
var Float32Array = require( '@stdlib/array/float32' );
8585

86-
var out = new Float64Array( 2 );
86+
var out = new Float32Array( 2 );
8787

88-
var y = frexp.assign( 4.0, out, 1, 0 );
89-
// returns <Float64Array>[ 0.5, 3 ]
88+
var y = frexpf.assign( 4.0, out, 1, 0 );
89+
// returns <Float32Array>[ 0.5, 3 ]
9090

9191
var bool = ( y === out );
9292
// returns true
@@ -100,23 +100,24 @@ var bool = ( y === out );
100100

101101
## Notes
102102

103-
- Care should be taken when reconstituting a [double-precision floating-point number][ieee754] from a normalized fraction and an exponent. For example,
103+
- Care should be taken when reconstituting a [single-precision floating-point number][ieee754] from a normalized fraction and an exponent. For example,
104104

105105
```javascript
106106
var pow = require( '@stdlib/math/base/special/pow' );
107+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
107108

108-
var x = 8.988939926493918e+307; // x ~ 2^1023
109+
var x = 1.7014118346046923e+38; // x ~ 2^127
109110

110-
var out = frexp( x );
111-
// returns [ 0.5000263811533315, 1024 ]
111+
var out = frexpf( x );
112+
// returns [ 0.5, 128 ]
112113

113114
// Naive reconstitution:
114-
var y = out[ 0 ] * pow( 2.0, out[ 1 ] );
115+
var y = f32( out[ 0 ] * f32( pow( 2.0, out[ 1 ] ) ) );
115116
// returns Infinity
116117

117-
// Account for 2^1024 evaluating as infinity by recognizing 2^1024 = 2^1 * 2^1023:
118-
y = out[ 0 ] * pow( 2.0, out[1]-1023 ) * pow( 2.0, 1023 );
119-
// returns 8.988939926493918e+307
118+
// Account for 2^128 evaluating as infinity by recognizing 2^128 = 2^1 * 2^127:
119+
y = f32( out[ 0 ] * f32( pow( 2.0, out[1]-127 ) ) * f32( pow( 2.0, 127 ) ) );
120+
// returns 1.7014118346046923e+38
120121
```
121122

122123
</section>
@@ -131,10 +132,11 @@ var bool = ( y === out );
131132

132133
```javascript
133134
var randu = require( '@stdlib/random/base/randu' );
134-
var round = require( '@stdlib/math/base/special/round' );
135+
var roundf = require( '@stdlib/math/base/special/roundf' );
135136
var pow = require( '@stdlib/math/base/special/pow' );
136-
var BIAS = require( '@stdlib/constants/float64/exponent-bias' );
137-
var frexp = require( '@stdlib/math/base/special/frexp' );
137+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
138+
var BIAS = require( '@stdlib/constants/float32/exponent-bias' );
139+
var frexpf = require( '@stdlib/math/base/special/frexpf' );
138140
139141
var sign;
140142
var frac;
@@ -147,18 +149,18 @@ var i;
147149
// Generate random numbers and break each into a normalized fraction and an integer power of two...
148150
for ( i = 0; i < 100; i++ ) {
149151
if ( randu() < 0.5 ) {
150-
sign = -1.0;
152+
sign = f32( -1.0 );
151153
} else {
152-
sign = 1.0;
154+
sign = f32( 1.0 );
153155
}
154-
frac = randu() * 10.0;
155-
exp = round( randu()*616.0 ) - 308;
156-
x = sign * frac * pow( 10.0, exp );
157-
f = frexp( x );
156+
frac = f32( randu()*10.0 );
157+
exp = roundf( randu()*76.0 ) - 38;
158+
x = f32( sign * frac * f32( pow( 10.0, exp ) ) );
159+
f = frexpf( x );
158160
if ( f[ 1 ] > BIAS ) {
159-
v = f[ 0 ] * pow( 2.0, f[1]-BIAS ) * pow( 2.0, BIAS );
161+
v = f32( f[ 0 ] * f32( pow(2.0, f[1]-BIAS) ) * f32( pow(2.0, BIAS) ) );
160162
} else {
161-
v = f[ 0 ] * pow( 2.0, f[ 1 ] );
163+
v = f32( f[ 0 ] * f32( pow( 2.0, f[ 1 ] ) ) );
162164
}
163165
console.log( '%d = %d * 2^%d = %d', x, f[ 0 ], f[ 1 ], v );
164166
}
@@ -191,29 +193,29 @@ for ( i = 0; i < 100; i++ ) {
191193
### Usage
192194

193195
```c
194-
#include "stdlib/math/base/special/frexp.h"
196+
#include "stdlib/math/base/special/frexpf.h"
195197
```
196198

197-
#### stdlib_base_frexp( x, frac, exp )
199+
#### stdlib_base_frexpf( x, frac, exp )
198200

199-
Splits a [double-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
201+
Splits a [single-precision floating-point number][ieee754] into a normalized fraction and an integer power of two.
200202

201203
```c
202204
#include <stdint.h>
203205
204-
double frac;
206+
float frac;
205207
int32_t exp;
206-
stdlib_base_frexp( 4.0, &frac, &exp );
208+
stdlib_base_frexpf( 4.0f, &frac, &exp );
207209
```
208210

209211
The function accepts the following arguments:
210212

211-
- **x**: `[in] double` input value.
212-
- **frac**: `[out] double*` destination for the normalized fraction.
213+
- **x**: `[in] float` input value.
214+
- **frac**: `[out] float*` destination for the normalized fraction.
213215
- **exp**: `[out] int32_t*` destination for the integer power of two.
214216

215217
```c
216-
void stdlib_base_frexp( const double x, double *frac, int32_t *exp );
218+
void stdlib_base_frexpf( const float x, float *frac, int32_t *exp );
217219
```
218220
219221
</section>
@@ -235,19 +237,19 @@ void stdlib_base_frexp( const double x, double *frac, int32_t *exp );
235237
### Examples
236238
237239
```c
238-
#include "stdlib/math/base/special/frexp.h"
240+
#include "stdlib/math/base/special/frexpf.h"
239241
#include <stdint.h>
240242
#include <stdio.h>
241243
#include <inttypes.h>
242244

243245
int main( void ) {
244-
const double x[] = { 4.0, 0.0, -0.0, 1.0, -1.0, 3.14, -3.14, 1.0e308, -1.0e308, 1.0/0.0, -1.0/0.0, 0.0/0.0 };
246+
const float x[] = { 4.0f, 0.0f, -0.0f, 1.0f, -1.0f, 3.14f, -3.14f, 1.0e38f, -1.0e38f, 1.0f/0.0f, -1.0f/0.0f, 0.0f/0.0f };
245247

246-
double frac;
248+
float frac;
247249
int32_t exp;
248250
int i;
249251
for ( i = 0; i < 12; i++ ) {
250-
stdlib_base_frexp( x[i], &frac, &exp );
252+
stdlib_base_frexpf( x[i], &frac, &exp );
251253
printf( "x: %f => frac: %f, exp: %" PRId32 "\n", x[i], frac, exp );
252254
}
253255
}
@@ -265,12 +267,6 @@ int main( void ) {
265267
266268
<section class="related">
267269
268-
* * *
269-
270-
## See Also
271-
272-
- <span class="package-name">[`@stdlib/math/base/special/ldexp`][@stdlib/math/base/special/ldexp]</span><span class="delimiter">: </span><span class="description">multiply a double-precision floating-point number by an integer power of two.</span>
273-
274270
</section>
275271
276272
<!-- /.related -->
@@ -281,12 +277,10 @@ int main( void ) {
281277
282278
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
283279
284-
[@stdlib/math/base/special/abs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/abs
280+
[@stdlib/math/base/special/absf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/absf
285281
286282
<!-- <related-links> -->
287283
288-
[@stdlib/math/base/special/ldexp]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/ldexp
289-
290284
<!-- </related-links> -->
291285
292286
</section>

lib/node_modules/@stdlib/math/base/special/frexpf/benchmark/benchmark.js

100644100755
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,10 +21,10 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isArray = require( '@stdlib/assert/is-array' );
2626
var pkg = require( './../package.json' ).name;
27-
var frexp = require( './../lib' );
27+
var frexpf = require( './../lib' );
2828

2929

3030
// MAIN //
@@ -34,11 +34,14 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -5.0e6, 5.0e6, {
38+
'dtype': 'float32'
39+
});
40+
3741
b.tic();
3842
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1.0e7 ) - 5.0e6;
40-
y = frexp( x );
41-
if ( typeof out !== 'object' ) {
43+
y = frexpf( x[ i%x.length ] );
44+
if ( typeof y !== 'object' ) {
4245
b.fail( 'should return an array' );
4346
}
4447
}
@@ -57,11 +60,13 @@ bench( pkg+':assign', function benchmark( b ) {
5760
var i;
5861

5962
out = [ 0.0, 0.0 ];
63+
x = uniform( 100, -5.0e6, 5.0e6, {
64+
'dtype': 'float32'
65+
});
6066

6167
b.tic();
6268
for ( i = 0; i < b.iterations; i++ ) {
63-
x = ( randu()*1.0e7 ) - 5.0e6;
64-
y = frexp.assign( x, out, 1, 0 );
69+
y = frexpf.assign( x[ i%x.length ], out, 1, 0 );
6570
if ( typeof out !== 'object' ) {
6671
b.fail( 'should return an array' );
6772
}

lib/node_modules/@stdlib/math/base/special/frexpf/benchmark/benchmark.native.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,17 +22,17 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var isArray = require( '@stdlib/assert/is-array' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

3030

3131
// VARIABLES //
3232

33-
var frexp = tryRequire( resolve( __dirname, './../lib/native.js' ) );
33+
var frexpf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3434
var opts = {
35-
'skip': ( frexp instanceof Error )
35+
'skip': ( frexpf instanceof Error )
3636
};
3737

3838

@@ -43,16 +43,19 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -5.0e6, 5.0e6, {
47+
'dtype': 'float32'
48+
});
49+
4650
b.tic();
4751
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1.0e7 ) - 5.0e6;
49-
y = frexp( x );
52+
y = frexpf( x[ i%x.length ] );
5053
if ( typeof y !== 'object' ) {
5154
b.fail( 'should return an array' );
5255
}
5356
}
5457
b.toc();
55-
if ( !isArray( y ) ) {
58+
if ( !isFloat32Array( y ) ) {
5659
b.fail( 'should return an array' );
5760
}
5861
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/frexpf/benchmark/c/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2018 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616
# limitations under the License.
1717
#/
1818

19-
2019
# VARIABLES #
2120

2221
ifndef VERBOSE

0 commit comments

Comments
 (0)