Skip to content

Commit 96f487a

Browse files
committed
refactor: implmentation and add test cases
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 673b831 commit 96f487a

40 files changed

Lines changed: 8195 additions & 130 deletions

lib/node_modules/@stdlib/array/float16/test/test.polyfill.js renamed to lib/node_modules/@stdlib/array/float16/lib/from_array.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,32 @@
2020

2121
// MODULES //
2222

23-
var tape = require( 'tape' );
24-
var ctor = require( './../lib/polyfill.js' );
23+
var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
24+
var toWord = require( '@stdlib/number/float16/base/to-word' );
2525

2626

27-
// TESTS //
27+
// MAIN //
2828

29-
tape( 'main export is a function', function test( t ) {
30-
t.ok( true, __filename );
31-
t.strictEqual( typeof ctor, 'function', 'main export is a function' );
32-
t.end();
33-
});
34-
35-
tape( 'the function throws an error when invoked', function test( t ) {
36-
t.throws( foo, Error, 'throws an error' );
37-
t.end();
29+
/**
30+
* Fills an output array with "unsigned 16-bit integer corresponding to the IEEE 754 binary representation of a half-precision floating-point number" values.
31+
*
32+
* @private
33+
* @param {Uint16Array} buf - output array
34+
* @param {Array} arr - input array
35+
* @returns {Uint16Array} output array
36+
*/
37+
function fromArray( buf, arr ) {
38+
var len;
39+
var i;
3840

39-
function foo() {
40-
var f = new ctor(); // eslint-disable-line no-unused-vars
41+
len = arr.length;
42+
for ( i = 0; i < len; i++ ) {
43+
buf[ i ] = toWord( float64ToFloat16( arr[ i ] ) );
4144
}
42-
});
45+
return buf;
46+
}
47+
48+
49+
// EXPORTS //
4350

44-
// TODO: tests
51+
module.exports = fromArray;

lib/node_modules/@stdlib/array/float16/lib/from_iterator.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
24+
var toWord = require( '@stdlib/number/float16/base/to-word' );
25+
26+
2127
// MAIN //
2228

2329
/**
@@ -37,7 +43,7 @@ function fromIterator( it ) {
3743
if ( v.done ) {
3844
break;
3945
}
40-
out.push( v.value );
46+
out.push( toWord( float64ToFloat16( v.value ) ) );
4147
}
4248
return out;
4349
}

lib/node_modules/@stdlib/array/float16/lib/from_iterator_map.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
24+
var toWord = require( '@stdlib/number/float16/base/to-word' );
25+
26+
2127
// MAIN //
2228

2329
/**
@@ -42,7 +48,7 @@ function fromIteratorMap( it, clbk, thisArg ) {
4248
break;
4349
}
4450
i += 1;
45-
out.push( clbk.call( thisArg, v.value, i ) );
51+
out.push( toWord( float64ToFloat16( clbk.call( thisArg, v.value, i ) ) ) );
4652
}
4753
return out;
4854
}

lib/node_modules/@stdlib/array/float16/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* @example
4545
* var Float16Array = require( '@stdlib/array/float16' );
4646
*
47-
* var arr = new Float16Array( [ true, false ] );
47+
* var arr = new Float16Array( [ 1.0, 2.0 ] );
4848
* // returns <Float16Array>
4949
*
5050
* var len = arr.length;

0 commit comments

Comments
 (0)