From be25e66b43db960bef077e885ca7776018cabb47 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 7 Dec 2025 18:07:51 +0530 Subject: [PATCH 1/9] feat: initial implementation for number-float16-ctor --- 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: 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: passed - task: lint_python status: missing_dependencies - task: lint_r status: na - task: lint_c_src status: missing_dependencies - 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 --- --- .../@stdlib/number/float16/ctor/README.md | 572 ++++++++++++++++++ .../float16/ctor/benchmark/benchmark.js | 125 ++++ .../float16/ctor/benchmark/julia/REQUIRE | 2 + .../float16/ctor/benchmark/julia/benchmark.jl | 144 +++++ .../ctor/benchmark/python/benchmark.py | 97 +++ .../ctor/include/stdlib/number/float16/ctor.h | 132 ++++ .../@stdlib/number/float16/ctor/lib/index.js | 40 ++ .../@stdlib/number/float16/ctor/lib/main.js | 144 +++++ .../@stdlib/number/float16/ctor/lib/tojson.js | 38 ++ .../number/float16/ctor/lib/tostring.js | 35 ++ .../@stdlib/number/float16/ctor/manifest.json | 49 ++ .../@stdlib/number/float16/ctor/package.json | 70 +++ .../@stdlib/number/float16/ctor/src/main.c | 440 ++++++++++++++ .../@stdlib/number/float16/ctor/test/test.js | 157 +++++ 14 files changed, 2045 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/README.md create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE create mode 100755 lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/manifest.json create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/package.json create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/src/main.c create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/test/test.js diff --git a/lib/node_modules/@stdlib/number/float16/ctor/README.md b/lib/node_modules/@stdlib/number/float16/ctor/README.md new file mode 100644 index 000000000000..7574f3b2f265 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/README.md @@ -0,0 +1,572 @@ + + +# Float16 + +> 16-bit half-precision floating-point number. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float16 = require( '@stdlib/number/float16/ctor' ); +``` + +#### Float16( value ) + +16-bit half-precision floating-point number constructor. + +```javascript +var x = new Float16( 5.0 ); +// returns +``` + +* * * + +## Properties + +#### Float16.BYTES_PER_ELEMENT + +Size (in bytes) of each component. + +```javascript +var nbytes = Float16.BYTES_PER_ELEMENT; +// returns 2 +``` + +#### Float16.prototype.BYTES_PER_ELEMENT + +Size (in bytes) of each component. + +```javascript +var x = new Float16( 5.0 ); + +var nbytes = x.BYTES_PER_ELEMENT; +// returns 2 +``` + +### Instance + +A `Float16` instance has the following properties... + +#### value + +A **read-only** property returning the float16 value as a `number`. + +```javascript +var x = new Float16( 5.0 ); + +var v = x.value; +// returns 5.0 +``` + +* * * + +## Methods + +### Accessor Methods + +These methods do **not** mutate a `Float16` instance and, instead return the float16 representation. + +#### Float16.prototype.toString() + +Returns a `string` representation of a `Float16` instance. + +```javascript +var x = new Float16( 5.0 ); +var str = x.toString(); +// returns '5' + +x = new Float16( -3.14 ); +str = x.toString(); +// returns '-3.140625' +``` + +#### Float16.prototype.toJSON() + +Returns a [JSON][json] representation of a `Float16` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Float16` instance. + +```javascript +var x = new Float16( 5.0 ); + +var o = x.toJSON(); +/* + { + "type": "Float16", + "value": 5.0 + } +*/ +``` + +To [revive][mdn-json-parse] a `Float16` number from a [JSON][json] `string`, see [@stdlib/number/float16/reviver][@stdlib/number/float16/reviver]. + +
+ + + +* * * + + + +
+ +## Notes + +- The float16 value is stored as a half-precision floating-point format [IEEE 754][ieee754] with 1 sign bit, 5 exponent bits, and 10 significand bits. +- Float16 has a range of approximately `±6.55e4` and precision of about 3-4 decimal digits. +- This is a **storage-only** type. All arithmetic operations should be performed by converting to `float32` or `float64`, computing, and converting back. + +
+ + + +* * * + + + +
+ +## Examples + + + +```javascript +var Float16 = require( '@stdlib/number/float16/ctor' ); + +var x = new Float16( 3.14 ); + +console.log( 'type: %s', typeof x ); +// => 'type: object' + +console.log( 'str: %s', x ); +// => 'str: 3.140625' + +console.log( 'value: %d', x.value ); +// => 'value: 3.140625' + +console.log( 'JSON: %s', JSON.stringify( x ) ); +// => 'JSON: {"type":"Float16","value":3.140625}' +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/number/float16/ctor.h" +``` + +#### stdlib_float16_t + +An opaque type definition for a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 3.14f ); + +float y = stdlib_float16_to_float32( x ); +// returns 3.140625f +``` + +#### stdlib_float16_from_float32( value ) + +Converts a single-precision floating-point number to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); +``` + +The function accepts the following arguments: + +- **value**: `[in] float` single-precision floating-point number. + +```c +stdlib_float16_t stdlib_float16_from_float32( const float value ); +``` + +#### stdlib_float16_from_float64( value ) + +Converts a double-precision floating-point number to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float64( 5.0 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] double` double-precision floating-point number. + +```c +stdlib_float16_t stdlib_float16_from_float64( const double value ); +``` + +#### stdlib_float16_to_float32( value ) + +Converts a half-precision floating-point number to a single-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); +float y = stdlib_float16_to_float32( x ); +// returns 5.0f +``` + +The function accepts the following arguments: + +- **value**: `[in] stdlib_float16_t` half-precision floating-point number. + +```c +float stdlib_float16_to_float32( const stdlib_float16_t value ); +``` + +#### stdlib_float16_to_float64( value ) + +Converts a half-precision floating-point number to a double-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); +double y = stdlib_float16_to_float64( x ); +// returns 5.0 +``` + +The function accepts the following arguments: + +- **value**: `[in] stdlib_float16_t` half-precision floating-point number. + +```c +double stdlib_float16_to_float64( const stdlib_float16_t value ); +``` + +#### stdlib_float16_from_int8( value ) + +Converts a signed 8-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_int8( 5 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] int8_t` signed 8-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_int8( const int8_t value ); +``` + +#### stdlib_float16_from_uint8( value ) + +Converts an unsigned 8-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_uint8( 200 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] uint8_t` unsigned 8-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ); +``` + +#### stdlib_float16_from_int16( value ) + +Converts a signed 16-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_int16( 1000 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] int16_t` signed 16-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_int16( const int16_t value ); +``` + +#### stdlib_float16_from_uint16( value ) + +Converts an unsigned 16-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_uint16( 50000 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] uint16_t` unsigned 16-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ); +``` + +#### stdlib_float16_from_int32( value ) + +Converts a signed 32-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_int32( 100000 ); +``` + +The function accepts the following arguments: + +- **value**: `[in] int32_t` signed 32-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_int32( const int32_t value ); +``` + +#### stdlib_float16_from_uint32( value ) + +Converts an unsigned 32-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_uint32( 100000U ); +``` + +The function accepts the following arguments: + +- **value**: `[in] uint32_t` unsigned 32-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ); +``` + +#### stdlib_float16_from_int64( value ) + +Converts a signed 64-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_int64( 1000000LL ); +``` + +The function accepts the following arguments: + +- **value**: `[in] int64_t` signed 64-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_int64( const int64_t value ); +``` + +#### stdlib_float16_from_uint64( value ) + +Converts an unsigned 64-bit integer to a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_uint64( 1000000ULL ); +``` + +The function accepts the following arguments: + +- **value**: `[in] uint64_t` unsigned 64-bit integer. + +```c +stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ); +``` + +#### stdlib_float16_to_int32( value ) + +Converts a half-precision floating-point number to a signed 32-bit integer (truncated toward zero). + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); +int32_t y = stdlib_float16_to_int32( x ); +// returns 2 +``` + +The function accepts the following arguments: + +- **value**: `[in] stdlib_float16_t` half-precision floating-point number. + +```c +int32_t stdlib_float16_to_int32( const stdlib_float16_t value ); +``` + +#### stdlib_float16_to_uint32( value ) + +Converts a half-precision floating-point number to an unsigned 32-bit integer (truncated toward zero). + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); +uint32_t y = stdlib_float16_to_uint32( x ); +// returns 2U +``` + +The function accepts the following arguments: + +- **value**: `[in] stdlib_float16_t` half-precision floating-point number. + +```c +uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ); +``` + +#### stdlib_float16_from_bits( bits ) + +Creates a half-precision floating-point number from raw bits. + +```c +stdlib_float16_t x = stdlib_float16_from_bits( 0x4000 ); +float y = stdlib_float16_to_float32( x ); +// returns 2.0f +``` + +The function accepts the following arguments: + +- **bits**: `[in] uint16_t` raw [IEEE 754][ieee754] binary16 bit pattern. + +```c +stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ); +``` + +#### stdlib_float16_to_bits( value ) + +Extracts the raw bit representation from a half-precision floating-point number. + +```c +stdlib_float16_t x = stdlib_float16_from_float32( 2.0f ); +uint16_t bits = stdlib_float16_to_bits( x ); +// returns 0x4000 +``` + +The function accepts the following arguments: + +- **value**: `[in] stdlib_float16_t` half-precision floating-point number. + +```c +uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/number/float16/ctor.h" +#include +#include + +int main( void ) { + stdlib_float16_t x; + float y; + int i; + + const float values[] = { + 5.0f, -2.0f, 0.0f, 0.0f/0.0f, 1.0f/0.0f, -1.0f/0.0f + }; + + for ( i = 0; i < 6; i++ ) { + x = stdlib_float16_from_float32( values[ i ] ); + y = stdlib_float16_to_float32( x ); + printf( "float32: %f => float16 => float32: %f\n", values[ i ], y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js new file mode 100644 index 000000000000..a626ff2ee89b --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var MAX_UINT16 = require( '@stdlib/constants/uint16/max' ); +var pkg = require( './../package.json' ).name; +var Float16 = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var y; + var x; + var i; + b.tic(); + + x = discreteUniform( 100, 0.0, MAX_UINT16 ); + + for ( i = 0; i < b.iterations; i++ ) { + y = new Float16( x[ i%x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !( y instanceof Float16 ) ) { + b.fail( 'should return a complex number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:value', function benchmark( b ) { + var v; + var x; + var y; + var i; + + x = discreteUniform( 100, 0.0, MAX_UINT16 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = new Float16( x[ i%x.length ] ); + v = y.value; + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':toString', function benchmark( b ) { + var o; + var x; + var y; + var i; + + x = discreteUniform( 100, 0.0, MAX_UINT16 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = new Float16( x[ i%x.length ] ); + o = y.toString(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':toJSON', function benchmark( b ) { + var o; + var x; + var y; + var i; + + x = discreteUniform( 100, 0.0, MAX_UINT16 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = new Float16( x[ i%x.length ] ); + o = y.toJSON(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE new file mode 100644 index 000000000000..98645e192e41 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 1.5 +BenchmarkTools 0.5.0 diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl new file mode 100755 index 000000000000..f620cc4066ed --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl @@ -0,0 +1,144 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import BenchmarkTools +using Printf + +# Benchmark variables: +name = "float16"; +repeats = 3; + +""" + print_version() + +Prints the TAP version. + +# Examples + +``` julia +julia> print_version() +``` +""" +function print_version() + @printf( "TAP version 13\n" ); +end + +""" + print_summary( total, passing ) + +Print the benchmark summary. + +# Arguments + +* `total`: total number of tests +* `passing`: number of passing tests + +# Examples + +``` julia +julia> print_summary( 3, 3 ) +``` +""" +function print_summary( total, passing ) + @printf( "#\n" ); + @printf( "1..%d\n", total ); # TAP plan + @printf( "# total %d\n", total ); + @printf( "# pass %d\n", passing ); + @printf( "#\n" ); + @printf( "# ok\n" ); +end + +""" + print_results( iterations, elapsed ) + +Print benchmark results. + +# Arguments + +* `iterations`: number of iterations +* `elapsed`: elapsed time (in seconds) + +# Examples + +``` julia +julia> print_results( 1000000, 0.131009101868 ) +``` +""" +function print_results( iterations, elapsed ) + rate = iterations / elapsed + + @printf( " ---\n" ); + @printf( " iterations: %d\n", iterations ); + @printf( " elapsed: %0.9f\n", elapsed ); + @printf( " rate: %0.9f\n", rate ); + @printf( " ...\n" ); +end + +""" + benchmark() + +Run a benchmark. + +# Notes + +* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. +* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. +* The elapsed time is in seconds. + +# Examples + +``` julia +julia> out = benchmark(); +``` +""" +function benchmark() + t = BenchmarkTools.@benchmark Float16( rand() ) samples=1e6 + + # Compute the total "elapsed" time and convert from nanoseconds to seconds: + s = sum( t.times ) / 1.0e9; + + # Determine the number of "iterations": + iter = length( t.times ); + + # Return the results: + [ iter, s ]; +end + +""" + main() + +Run benchmarks. + +# Examples + +``` julia +julia> main(); +``` +""" +function main() + print_version(); + for i in 1:repeats + @printf( "# julia::%s\n", name ); + results = benchmark(); + print_results( results[ 1 ], results[ 2 ] ); + @printf( "ok %d benchmark finished\n", i ); + end + print_summary( repeats, repeats ); +end + +main(); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py new file mode 100644 index 000000000000..2abd60e8bc17 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Benchmark complex.""" + +from __future__ import print_function +import timeit + +NAME = "float16" +REPEATS = 3 +ITERATIONS = 1000000 + + +def print_version(): + """Print the TAP version.""" + print("TAP version 13") + + +def print_summary(total, passing): + """Print the benchmark summary. + + # Arguments + + * `total`: total number of tests + * `passing`: number of passing tests + + """ + print("#") + print("1.." + str(total)) # TAP plan + print("# total " + str(total)) + print("# pass " + str(passing)) + print("#") + print("# ok") + + +def print_results(elapsed): + """Print benchmark results. + + # Arguments + + * `elapsed`: elapsed time (in seconds) + + # Examples + + ``` python + python> print_results(0.131009101868) + ``` + """ + rate = ITERATIONS / elapsed + + print(" ---") + print(" iterations: " + str(ITERATIONS)) + print(" elapsed: " + str(elapsed)) + print(" rate: " + str(rate)) + print(" ...") + + +def benchmark(): + """Run the benchmark and print benchmark results.""" + setup = "from random import random;" + stmt = "z = float(float(random()))" + + t = timeit.Timer(stmt, setup=setup) + + print_version() + + for i in range(REPEATS): + print("# python::" + NAME) + elapsed = t.timeit(number=ITERATIONS) + print_results(elapsed) + print("ok " + str(i+1) + " benchmark finished") + + print_summary(REPEATS, REPEATS) + + +def main(): + """Run the benchmark.""" + benchmark() + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h new file mode 100644 index 000000000000..ee7fc62e7e4d --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h @@ -0,0 +1,132 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef STDLIB_NUMBER_FLOAT16_CTOR_H +#define STDLIB_NUMBER_FLOAT16_CTOR_H + +#include +#include + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* An opaque type definition for a half-precision floating-point number. +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 3.14f ); +* +* float y = stdlib_float16_to_float32( x ); +* // returns 3.140625f +*/ +typedef struct { + /** + * Raw IEEE 754 binary16 bit representation. + */ + uint16_t bits; +} stdlib_float16_t; + +/** +* Creates a half-precision floating-point number from a single-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_float32( const float value ); + +/** +* Creates a half-precision floating-point number from a double-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_float64( const double value ); + +/** +* Converts a half-precision floating-point number to single-precision floating-point number. +*/ +float stdlib_float16_to_float32( const stdlib_float16_t value ); + +/** +* Converts a half-precision floating-point number to double-precision floating-point number. +*/ +double stdlib_float16_to_float64( const stdlib_float16_t value ); + +/** +* Converts a signed 8-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_int8( const int8_t value ); + +/** +* Converts an unsigned 8-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ); + +/** +* Converts a signed 16-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_int16( const int16_t value ); + +/** +* Converts an unsigned 16-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ); + +/** +* Converts a signed 32-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_int32( const int32_t value ); + +/** +* Converts an unsigned 32-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ); + +/** +* Converts a signed 64-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_int64( const int64_t value ); + +/** +* Converts an unsigned 64-bit integer to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ); + +/** +* Converts a half-precision floating-point number to a signed 32-bit integer. +*/ +int32_t stdlib_float16_to_int32( const stdlib_float16_t value ); + +/** +* Converts a half-precision floating-point number to an unsigned 32-bit integer. +*/ +uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ); + +/** +* Creates a half-precision floating-point number from raw bits. +*/ +stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ); + +/** +* Extracts the raw bit representation from a half-precision floating-point number. +*/ +uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_NUMBER_FLOAT16_CTOR_H diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/index.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/index.js new file mode 100644 index 000000000000..e000e96cb7d2 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* 16-bit half-precision floating-point number constructor. +* +* @module @stdlib/number/float16/ctor +* +* @example +* var Float16 = require( '@stdlib/number/float16/ctor' ); +* +* var x = new Float16( 5.0 ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js new file mode 100644 index 000000000000..399e1d72d992 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var defineProperty = require( '@stdlib/utils/define-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var format = require( '@stdlib/string/format' ); +var toStr = require( './tostring.js' ); +var toJSON = require( './tojson.js' ); + + +// MAIN // + +/** +* 16-bit half-precision floating-point number constructor. +* +* @constructor +* @param {number} value - numeric value +* @throws {TypeError} must invoke using the `new` keyword +* @throws {TypeError} value must be a number +* @returns {Float16} 16-bit half-precision floating-point number +* +* @example +* var x = new Float16( 5.0 ); +* // returns +*/ +function Float16( value ) { + if ( !( this instanceof Float16 ) ) { + throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' ); + } + if ( !isNumber( value ) ) { + throw new TypeError( format( 'invalid argument. Value must be a number. Value: `%s`.', value ) ); + } + + // Store as uint16 bits (internal representation) + defineProperty( this, '_bits', { + 'configurable': false, + 'enumerable': false, + 'writable': false, + 'value': float64ToFloat16( value ) + }); + + // Define read-only value property that converts back to number + defineProperty( this, 'value', { + 'configurable': false, + 'enumerable': true, + 'get': function getValue() { // eslint-disable-line no-restricted-syntax + return this._bits; + } + }); + + return this; +} + +/** +* Size (in bytes) of each component. +* +* @name BYTES_PER_ELEMENT +* @memberof Float16 +* @type {integer} +* @returns {integer} size of each component +* +* @example +* var nbytes = Float16.BYTES_PER_ELEMENT; +* // returns 2 +*/ +setReadOnly( Float16, 'BYTES_PER_ELEMENT', 2 ); + +/** +* Size (in bytes) of each component. +* +* @name BYTES_PER_ELEMENT +* @memberof Float16.prototype +* @type {integer} +* @returns {integer} size of each component +* +* @example +* var x = new Float16( 5.0 ); +* +* var nbytes = x.BYTES_PER_ELEMENT; +* // returns 2 +*/ +setReadOnly( Float16.prototype, 'BYTES_PER_ELEMENT', 2 ); + +/** +* Serializes a half-precision floating-point number as a string. +* +* @name toString +* @memberof Float16.prototype +* @type {Function} +* @returns {string} serialized half-precision floating-point number +* +* @example +* var x = new Float16( 5.0 ); +* +* var str = x.toString(); +* // returns '5' +*/ +setReadOnly( Float16.prototype, 'toString', toStr ); + +/** +* Serializes a half-precision floating-point number as a JSON object. +* +* ## Notes +* +* - `JSON.stringify()` implicitly calls this method when stringifying a `Float16` instance. +* +* @name toJSON +* @memberof Float16.prototype +* @type {Function} +* @returns {Object} serialized half-precision floating-point number +* +* @example +* var x = new Float16( 5.0 ); +* +* var obj = x.toJSON(); +* // returns { 'type': 'Float16', 'value': 5.0 } +*/ +setReadOnly( Float16.prototype, 'toJSON', toJSON ); + + +// EXPORTS // + +module.exports = Float16; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js new file mode 100644 index 000000000000..3102401bd201 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Serializes a half-precision floating-point number as a JSON object. +* +* @private +* @returns {Object} JSON representation +*/ +function toJSON() { + /* eslint-disable no-invalid-this */ + var out = {}; + out.type = 'Float16'; + out.value = this.value; + return out; +} + + +// EXPORTS // + +module.exports = toJSON; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js new file mode 100644 index 000000000000..ae5575b11644 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Serializes a half-precision floating-point number as a string. +* +* @private +* @returns {string} serialized half-precision floating-point number +*/ +function toString() { // eslint-disable-line stdlib/no-redeclare + /* eslint-disable no-invalid-this */ + return '' + this.value; +} + + +// EXPORTS // + +module.exports = toString; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/manifest.json b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json new file mode 100644 index 000000000000..2f66c1c8e50d --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json @@ -0,0 +1,49 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/constants/float32/sign-mask", + "@stdlib/constants/float32/exponent-mask", + "@stdlib/constants/float32/significand-mask", + "@stdlib/constants/float32/num-significand-bits", + "@stdlib/constants/float16/sign-mask", + "@stdlib/constants/float16/exponent-mask", + "@stdlib/constants/float16/significand-mask", + "@stdlib/constants/float16/num-significand-bits", + "@stdlib/number/float32/base/exponent", + "@stdlib/math/base/special/exp2" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/package.json b/lib/node_modules/@stdlib/number/float16/ctor/package.json new file mode 100644 index 000000000000..19c43238d2fb --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/number/float16/ctor", + "version": "0.0.0", + "description": "16-bit half-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "constructor", + "ctor", + "floating-point", + "float16", + "16-bit", + "integer", + "float", + "half", + "half-precision", + "ieee754" + ] +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c new file mode 100644 index 000000000000..2bbfdaa7de25 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c @@ -0,0 +1,440 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/number/float16/ctor.h" +#include "stdlib/constants/float32/sign_mask.h" +#include "stdlib/constants/float32/exponent_mask.h" +#include "stdlib/constants/float32/significand_mask.h" +#include "stdlib/constants/float32/num_significand_bits.h" +#include "stdlib/constants/float16/sign_mask.h" +#include "stdlib/constants/float16/exponent_mask.h" +#include "stdlib/constants/float16/significand_mask.h" +#include "stdlib/constants/float16/num_significand_bits.h" +#include "stdlib/number/float32/base/exponent.h" +#include +#include + +// VARIABLES // + +static const uint32_t FLOAT32_MAX_EXPONENT = 255; +static const uint32_t FLOAT16_MAX_EXPONENT = 31; +static const uint16_t UINT16_PINF = 0x7C00; // 0x7C00 = 31744 => 0 11111 0000000000 +static const uint16_t UINT16_NINF = 0xFC00; // 0xFC00 = 64512 => 1 11111 0000000000 +static const uint16_t UINT16_NAN = 0x7E00; // 0x7E00 = 32256 => 0 11111 1000000000 +static const uint16_t UINT16_POSITIVE_ZERO = 0x0000; // 0x0000 = 0 => 0 00000 0000000000 +static const uint16_t UINT16_NEGATIVE_ZERO = 0x8000; // 0x8000 = 32768 => 1 00000 0000000000 +static const uint32_t FLOAT32_IMPLICIT_BIT = 0x800000; // 0x800000 = 8388608 => 0 00000001 00000000000000000000000 +static const uint32_t FLOAT32_STICKY_MASK = 0xFFF; // 0xFFF = 4095 => 0 00000000 00000000000111111111111 +static const uint16_t MAX_MANTISSA = 0x3FF; // 0x3FF = 1023 => 0 00000 1111111111 + +/** +* Converts a single-precision floating-point number to a half-precision floating-point number. +* +* @param value single-precision floating-point number +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); +*/ +stdlib_float16_t stdlib_float16_from_float32( const float value ) { + stdlib_float16_t result; + uint32_t f32Mantissa; + uint32_t f32Exponent; + uint32_t f16Mantissa; + uint32_t sticky_bits; + int32_t f16Exponent; + uint32_t round_bit; + uint32_t sign; + uint32_t f32; + int shift; + + // Copy float bits to uint32_t + memcpy( &f32, &value, sizeof(float) ); + + // Extract sign bit and shift to bit 15: + sign = ( f32 & STDLIB_CONSTANT_FLOAT32_SIGN_MASK ) >> 16; + + // Extract exponent bits: + f32Exponent = ( f32 & STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) >> STDLIB_CONSTANT_FLOAT32_NUM_SIGNIFICAND_BITS; + + // Extract mantissa bits: + f32Mantissa = f32 & STDLIB_CONSTANT_FLOAT32_SIGNIFICAND_MASK; + + // Handle special cases... + if ( f32Exponent == FLOAT32_MAX_EXPONENT ) { + if ( f32Mantissa == 0 ) { + if ( sign ) { + result.bits = UINT16_NINF; // -Infinity + } else { + result.bits = UINT16_PINF; // +Infinity + } + } else { + result.bits = UINT16_NAN; // NaN + } + return result; + } + + if ( f32Exponent == 0 && f32Mantissa == 0 ) { + if (sign) { + result.bits = UINT16_NEGATIVE_ZERO; + } else { + result.bits = UINT16_POSITIVE_ZERO; + } + return result; + } + + // Convert exponent from float32 bias (127) to float16 bias (15) + f16Exponent = stdlib_base_float32_exponent( value ) + 15; + + // Handle overflow (infinity in float16)... + if ( f16Exponent >= 31 ) { + if ( sign ) { + result.bits = UINT16_NINF; // -Infinity + } else { + result.bits = UINT16_PINF; // +Infinity + } + return result; + } + + // Handle underflow (subnormal or zero in float16)... + if ( f16Exponent <= 0 ) { + // Check if the value is too small to be represented even as a subnormal float16 number: + if ( f16Exponent < -10 ) { + // Too small, round to zero + if ( sign ) { + result.bits = UINT16_NEGATIVE_ZERO; + } else { + result.bits = UINT16_POSITIVE_ZERO; + } + return result; + } + + // Calculate the amount of right shift needed to denormalize the mantissa for subnormal representation: + shift = 1 - f16Exponent; + + // Create an 11-bit mantissa by adding the implicit leading 1 bit and extracting the top 10 bits from mantissa: + f32Mantissa |= FLOAT32_IMPLICIT_BIT; + f16Mantissa = f32Mantissa >> ( 13 + shift ); + + // Round to nearest, ties to even + round_bit = ( f32Mantissa >> ( 12 + shift ) ) & 1; + sticky_bits = f32Mantissa & ( ( 1u << ( 12 + shift ) ) - 1 ); + + if ( round_bit && ( sticky_bits || ( f16Mantissa & 1 ) ) ) { + f16Mantissa += 1; + } + + result.bits = (uint16_t)(sign | f16Mantissa); + return result; + } + + // Extract the top 10 bits of the mantissa from 23 bits: + f16Mantissa = f32Mantissa >> 13; + + // Extract the round bit (the first bit that will be truncated): + round_bit = ( f32Mantissa >> 12 ) & 1; + + // Check sticky bits (all bits below bit 12): + sticky_bits = f32Mantissa & FLOAT32_STICKY_MASK; + + if ( round_bit && ( sticky_bits || ( f16Mantissa & 1 ) ) ) { + f16Mantissa += 1; + + // Check for mantissa overflow (carries into exponent)... + if ( f16Mantissa > MAX_MANTISSA ) { + f16Exponent += 1; + f16Mantissa = 0; + + // Check for exponent overflow... + if ( f16Exponent >= 31 ) { + if ( sign ) { + result.bits = UINT16_NINF; // -Infinity + } else { + result.bits = UINT16_PINF; // +Infinity + } + return result; + } + } + } + + // Combine sign (1 bit), exponent (5 bits), and mantissa (10 bits): + result.bits = (uint16_t)(sign | (f16Exponent << 10) | f16Mantissa); + return result; +} + +/** +* Converts a double-precision floating-point number to a half-precision floating-point number. +* +* @param value double-precision floating-point number +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float64( 5.0 ); +*/ +stdlib_float16_t stdlib_float16_from_float64( const double value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts a half-precision floating-point number to a single-precision floating-point number. +* +* @param value half-precision floating-point number +* @return single-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 2.5f ); +* float y = stdlib_float16_to_float32( x ); +*/ +float stdlib_float16_to_float32( const stdlib_float16_t value ) { + uint32_t f32Exponent; + uint32_t f16Mantissa; + uint32_t f16Exponent; + uint32_t sign; + uint32_t f32; + uint16_t f16; + float result; + + f16 = value.bits; + + // Extract sign bit and shift left 16 bits: + sign = ((uint32_t)(f16 & STDLIB_CONSTANT_FLOAT16_SIGN_MASK)) << 16; + + // Extract exponent bits: + f16Exponent = (f16 & STDLIB_CONSTANT_FLOAT16_EXPONENT_MASK) >> STDLIB_CONSTANT_FLOAT16_NUM_SIGNIFICAND_BITS; + + // Extract mantissa bits: + f16Mantissa = f16 & STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK; + + // Handle special cases... + if ( f16Exponent == 0 ) { + if ( f16Mantissa == 0 ) { + // Zero + f32 = sign; + memcpy( &result, &f32, sizeof(float) ); + return result; + } + + // Denormalized number - convert to normalized float32 + f32Exponent = 1; + while ( ( f16Mantissa & 0x0400 ) == 0 ) { + f16Mantissa <<= 1; + f32Exponent -= 1; + } + + f16Mantissa &= STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK; + f32Exponent = 127 - 15 + f32Exponent; + f32 = sign | (f32Exponent << 23) | (f16Mantissa << 13); + memcpy( &result, &f32, sizeof(float) ); + return result; + } + + if (f16Exponent == FLOAT16_MAX_EXPONENT) { + // Infinity or NaN + f32 = sign | STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK | (f16Mantissa << 13); + memcpy( &result, &f32, sizeof(float) ); + return result; + } + + // Normal case: convert exponent from float16 bias (15) to float32 bias (127) + f32Exponent = f16Exponent - 15 + 127; + f32 = sign | (f32Exponent << 23) | (f16Mantissa << 13); + memcpy( &result, &f32, sizeof(float) ); + return result; +} + +/** +* Converts a half-precision floating-point number to a double-precision floating-point number. +* +* @param value half-precision floating-point number +* @return double-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float64( 2.5 ); +* double y = stdlib_float16_to_float64( x ); +*/ +double stdlib_float16_to_float64( const stdlib_float16_t value ) { + return (double)stdlib_float16_to_float32( value ); +} + +/** +* Converts a signed 8-bit integer to half-precision floating-point number. +* +* @param value signed 8-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_int8( 42 ); +*/ +stdlib_float16_t stdlib_float16_from_int8( const int8_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts an unsigned 8-bit integer to half-precision floating-point number. +* +* @param value unsigned 8-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_uint8( 200 ); +*/ +stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts a signed 16-bit integer to half-precision floating-point number. +* +* @param value signed 16-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_int16( 1000 ); +*/ +stdlib_float16_t stdlib_float16_from_int16( const int16_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts an unsigned 16-bit integer to half-precision floating-point number. +* +* @param value unsigned 16-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_uint16( 50000 ); +*/ +stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts a signed 32-bit integer to half-precision floating-point number. +* +* @param value signed 32-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_int32( 100000 ); +*/ +stdlib_float16_t stdlib_float16_from_int32( const int32_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts an unsigned 32-bit integer to half-precision floating-point number. +* +* @param value unsigned 32-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_uint32( 100000U ); +*/ +stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts a signed 64-bit integer to half-precision floating-point number. +* +* @param value signed 64-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_int64( 1000000LL ); +*/ +stdlib_float16_t stdlib_float16_from_int64( const int64_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts an unsigned 64-bit integer to half-precision floating-point number. +* +* @param value unsigned 64-bit integer +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_uint64( 1000000ULL ); +*/ +stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ) { + return stdlib_float16_from_float32( (float)value ); +} + +/** +* Converts a half-precision floating-point number to a signed 32-bit integer. +* +* @param value half-precision floating-point number +* @return signed 32-bit integer (truncated toward zero) +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); +* int32_t y = stdlib_float16_to_int32( x ); +*/ +int32_t stdlib_float16_to_int32( const stdlib_float16_t value ) { + return (int32_t)stdlib_float16_to_float32( value ); +} + +/** +* Converts a half-precision floating-point number to an unsigned 32-bit integer. +* +* @param value half-precision floating-point number +* @return unsigned 32-bit integer (truncated toward zero) +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); +* uint32_t y = stdlib_float16_to_uint32( x ); +*/ +uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ) { + float f = stdlib_float16_to_float32( value ); + if (f < 0.0f) { + return 0; + } + return (uint32_t)f; +} + +/** +* Creates a half-precision floating-point number from raw bits. +* +* @param bits raw IEEE 754 binary16 bit pattern +* @return half-precision floating-point number +* +* @example +* stdlib_float16_t x = stdlib_float16_from_bits( 0x4000 ); +* float y = stdlib_float16_to_float32( x ); +* // returns 2.0f +*/ +stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ) { + stdlib_float16_t result; + result.bits = bits; + return result; +} + +/** +* Extracts the raw bit representation from a half-precision floating-point number. +* +* @param value half-precision floating-point number +* @return raw IEEE 754 binary16 bit pattern +* +* @example +* stdlib_float16_t x = stdlib_float16_from_float32( 2.0f ); +* uint16_t bits = stdlib_float16_to_bits( x ); +* // returns 0x4000 +*/ +uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ) { + return value.bits; +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/test/test.js b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js new file mode 100644 index 000000000000..a8c505b2f161 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Float16 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var x = new Float16( 5.0 ); + t.strictEqual( x instanceof Float16, true, 'is an instance' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided a value component which is not a number', function test( t ) { + var values; + var i; + + values = [ + '5', + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var x = new Float16( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor requires the `new` keyword', function test( t ) { + var ctor = Float16; + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + ctor( 5.0 ); + } +}); + +tape( 'the constructor has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Float16, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Float16.BYTES_PER_ELEMENT = 4; + } +}); + +tape( 'the constructor prototype has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Float16.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16.prototype.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Float16.prototype.BYTES_PER_ELEMENT = 4; + } +}); + +tape( 'the constructor returns an instance having a property for getting the value', function test( t ) { + var x = new Float16( 5.0 ); + t.strictEqual( x.value, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance which throws an error when attempting to mutate the value', function test( t ) { + var x = new Float16( 5.0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + x.value = -5.0; + } +}); + +tape( 'the constructor returns an instance which stores value component as half-precision floating-point numbers', function test( t ) { + var x = new Float16( 3.14 ); + + t.strictEqual( x.value, 3.140625, 'stores as half-precision' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports serializing an instance as a string', function test( t ) { + var x; + + x = new Float16( 5.0 ); + t.strictEqual( x.toString(), '5', 'returns expected value' ); + + x = new Float16( -5.0 ); + t.strictEqual( x.toString(), '-5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports serializing an instance as a JSON object', function test( t ) { + var expected; + var x; + + x = new Float16( 5.0 ); + expected = { + 'type': 'Float16', + 'value': 5.0 + }; + t.deepEqual( x.toJSON(), expected, 'returns expected value' ); + t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + + x = new Float16( -5.0 ); + expected = { + 'type': 'Float16', + 'value': -5.0 + }; + t.deepEqual( x.toJSON(), expected, 'returns expected value' ); + t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + + t.end(); +}); From a11f7d648f47fd62e1ac3e3809a476144450c33b Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 8 Dec 2025 23:44:31 +0530 Subject: [PATCH 2/9] refactor: changes as suggested --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - 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: passed - task: lint_license_headers status: passed --- --- .../@stdlib/number/float16/ctor/README.md | 302 +----------- .../float16/ctor/benchmark/benchmark.js | 125 ----- .../float16/ctor/benchmark/julia/REQUIRE | 2 - .../float16/ctor/benchmark/julia/benchmark.jl | 144 ------ .../ctor/benchmark/python/benchmark.py | 97 ---- .../@stdlib/number/float16/ctor/docs/repl.txt | 56 +++ .../number/float16/ctor/docs/types/index.d.ts | 90 ++++ .../number/float16/ctor/docs/types/test.ts | 57 +++ .../number/float16/ctor/examples/index.js | 35 ++ .../ctor/include/stdlib/number/float16/ctor.h | 80 ---- .../@stdlib/number/float16/ctor/manifest.json | 17 +- .../@stdlib/number/float16/ctor/package.json | 1 - .../@stdlib/number/float16/ctor/src/main.c | 440 ------------------ 13 files changed, 246 insertions(+), 1200 deletions(-) delete mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE delete mode 100755 lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl delete mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/examples/index.js delete mode 100644 lib/node_modules/@stdlib/number/float16/ctor/src/main.c diff --git a/lib/node_modules/@stdlib/number/float16/ctor/README.md b/lib/node_modules/@stdlib/number/float16/ctor/README.md index 7574f3b2f265..ee1f751b8d00 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/README.md +++ b/lib/node_modules/@stdlib/number/float16/ctor/README.md @@ -211,278 +211,12 @@ console.log( 'JSON: %s', JSON.stringify( x ) ); An opaque type definition for a half-precision floating-point number. ```c -stdlib_float16_t x = stdlib_float16_from_float32( 3.14f ); - -float y = stdlib_float16_to_float32( x ); -// returns 3.140625f -``` - -#### stdlib_float16_from_float32( value ) - -Converts a single-precision floating-point number to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); -``` - -The function accepts the following arguments: - -- **value**: `[in] float` single-precision floating-point number. - -```c -stdlib_float16_t stdlib_float16_from_float32( const float value ); -``` - -#### stdlib_float16_from_float64( value ) - -Converts a double-precision floating-point number to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_float64( 5.0 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] double` double-precision floating-point number. - -```c -stdlib_float16_t stdlib_float16_from_float64( const double value ); -``` - -#### stdlib_float16_to_float32( value ) - -Converts a half-precision floating-point number to a single-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); -float y = stdlib_float16_to_float32( x ); -// returns 5.0f -``` - -The function accepts the following arguments: - -- **value**: `[in] stdlib_float16_t` half-precision floating-point number. - -```c -float stdlib_float16_to_float32( const stdlib_float16_t value ); -``` - -#### stdlib_float16_to_float64( value ) - -Converts a half-precision floating-point number to a double-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); -double y = stdlib_float16_to_float64( x ); -// returns 5.0 -``` - -The function accepts the following arguments: - -- **value**: `[in] stdlib_float16_t` half-precision floating-point number. - -```c -double stdlib_float16_to_float64( const stdlib_float16_t value ); -``` - -#### stdlib_float16_from_int8( value ) - -Converts a signed 8-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_int8( 5 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] int8_t` signed 8-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_int8( const int8_t value ); -``` - -#### stdlib_float16_from_uint8( value ) - -Converts an unsigned 8-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_uint8( 200 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] uint8_t` unsigned 8-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ); -``` - -#### stdlib_float16_from_int16( value ) - -Converts a signed 16-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_int16( 1000 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] int16_t` signed 16-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_int16( const int16_t value ); -``` - -#### stdlib_float16_from_uint16( value ) - -Converts an unsigned 16-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_uint16( 50000 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] uint16_t` unsigned 16-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ); -``` - -#### stdlib_float16_from_int32( value ) - -Converts a signed 32-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_int32( 100000 ); -``` - -The function accepts the following arguments: - -- **value**: `[in] int32_t` signed 32-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_int32( const int32_t value ); -``` - -#### stdlib_float16_from_uint32( value ) - -Converts an unsigned 32-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_uint32( 100000U ); -``` - -The function accepts the following arguments: - -- **value**: `[in] uint32_t` unsigned 32-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ); -``` - -#### stdlib_float16_from_int64( value ) - -Converts a signed 64-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_int64( 1000000LL ); -``` - -The function accepts the following arguments: - -- **value**: `[in] int64_t` signed 64-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_int64( const int64_t value ); -``` - -#### stdlib_float16_from_uint64( value ) - -Converts an unsigned 64-bit integer to a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_uint64( 1000000ULL ); -``` - -The function accepts the following arguments: - -- **value**: `[in] uint64_t` unsigned 64-bit integer. - -```c -stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ); -``` - -#### stdlib_float16_to_int32( value ) - -Converts a half-precision floating-point number to a signed 32-bit integer (truncated toward zero). - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); -int32_t y = stdlib_float16_to_int32( x ); -// returns 2 -``` - -The function accepts the following arguments: - -- **value**: `[in] stdlib_float16_t` half-precision floating-point number. - -```c -int32_t stdlib_float16_to_int32( const stdlib_float16_t value ); -``` - -#### stdlib_float16_to_uint32( value ) - -Converts a half-precision floating-point number to an unsigned 32-bit integer (truncated toward zero). - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); -uint32_t y = stdlib_float16_to_uint32( x ); -// returns 2U -``` - -The function accepts the following arguments: - -- **value**: `[in] stdlib_float16_t` half-precision floating-point number. - -```c -uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ); -``` - -#### stdlib_float16_from_bits( bits ) - -Creates a half-precision floating-point number from raw bits. - -```c -stdlib_float16_t x = stdlib_float16_from_bits( 0x4000 ); -float y = stdlib_float16_to_float32( x ); -// returns 2.0f -``` - -The function accepts the following arguments: - -- **bits**: `[in] uint16_t` raw [IEEE 754][ieee754] binary16 bit pattern. - -```c -stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ); -``` - -#### stdlib_float16_to_bits( value ) - -Extracts the raw bit representation from a half-precision floating-point number. - -```c -stdlib_float16_t x = stdlib_float16_from_float32( 2.0f ); -uint16_t bits = stdlib_float16_to_bits( x ); -// returns 0x4000 -``` - -The function accepts the following arguments: - -- **value**: `[in] stdlib_float16_t` half-precision floating-point number. - -```c -uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ); +typedef struct { + /** + * Raw IEEE 754 binary16 bit representation. + */ + uint16_t bits; +} stdlib_float16_t; ``` @@ -501,30 +235,6 @@ uint16_t stdlib_float16_to_bits( const stdlib_float16_t value );
-### Examples - -```c -#include "stdlib/number/float16/ctor.h" -#include -#include - -int main( void ) { - stdlib_float16_t x; - float y; - int i; - - const float values[] = { - 5.0f, -2.0f, 0.0f, 0.0f/0.0f, 1.0f/0.0f, -1.0f/0.0f - }; - - for ( i = 0; i < 6; i++ ) { - x = stdlib_float16_from_float32( values[ i ] ); - y = stdlib_float16_to_float32( x ); - printf( "float32: %f => float16 => float32: %f\n", values[ i ], y ); - } -} -``` -
diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js deleted file mode 100644 index a626ff2ee89b..000000000000 --- a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,125 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var MAX_UINT16 = require( '@stdlib/constants/uint16/max' ); -var pkg = require( './../package.json' ).name; -var Float16 = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var y; - var x; - var i; - b.tic(); - - x = discreteUniform( 100, 0.0, MAX_UINT16 ); - - for ( i = 0; i < b.iterations; i++ ) { - y = new Float16( x[ i%x.length ] ); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !( y instanceof Float16 ) ) { - b.fail( 'should return a complex number' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:value', function benchmark( b ) { - var v; - var x; - var y; - var i; - - x = discreteUniform( 100, 0.0, MAX_UINT16 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = new Float16( x[ i%x.length ] ); - v = y.value; - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':toString', function benchmark( b ) { - var o; - var x; - var y; - var i; - - x = discreteUniform( 100, 0.0, MAX_UINT16 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = new Float16( x[ i%x.length ] ); - o = y.toString(); - if ( typeof o !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof o !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var x; - var y; - var i; - - x = discreteUniform( 100, 0.0, MAX_UINT16 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = new Float16( x[ i%x.length ] ); - o = y.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e192e41..000000000000 --- a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl deleted file mode 100755 index f620cc4066ed..000000000000 --- a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import BenchmarkTools -using Printf - -# Benchmark variables: -name = "float16"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Float16( rand() ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py deleted file mode 100644 index 2abd60e8bc17..000000000000 --- a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/python/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark complex.""" - -from __future__ import print_function -import timeit - -NAME = "float16" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "from random import random;" - stmt = "z = float(float(random()))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt new file mode 100644 index 000000000000..3ec1137f3aed --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt @@ -0,0 +1,56 @@ + +{{alias}}( value ) + 16-bit half-precision floating-point number constructor. + + Value component is stored as half-precision floating-point numbers. + + Parameters + ---------- + value: number + Numeric value. + + Returns + ------- + x : number + Half-precision floating-point number. + + Examples + -------- + > var x = new {{alias}}( 3.14 ) + + > x.value + 3.140625 + + +{{alias}}.BYTES_PER_ELEMENT + Size (in bytes) of each component. + + Returns + ------- + v: integer + Size (in bytes) of each component. + + Examples + -------- + > var s = {{alias}}.BYTES_PER_ELEMENT + 2 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Size (in bytes) of each component. + + Returns + ------- + s: integer + Size (in bytes) of each component. + + Examples + -------- + > var x = new {{alias}}( 5.0 ) + + > var s = x.BYTES_PER_ELEMENT + 2 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts new file mode 100644 index 000000000000..2e5ed0c542d2 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts @@ -0,0 +1,90 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* 16-bit half-precision floating-point number. +*/ +declare class Float16 { + /** + * 64-bit half-precision floating-point number constructor. + * + * @param value - numeric value + * @returns 16-bit half-precision floating-point number + * + * @example + * var x = new Float16( 5.0 ); + * // returns + */ + constructor( value: number ); + + /** + * Read-only property returning the value component. + * + * @returns value component + */ + readonly value: number; + + /** + * Size (in bytes) of each component. + * + * @returns size of each component + * + * @example + * var nbytes = Float16.BYTES_PER_ELEMENT; + * // returns 2 + */ + readonly BYTES_PER_ELEMENT: 2; + + /** + * Serializes a half-precision floating-point number as a string. + * + * @returns serialized half-precision floating-point number + * + * @example + * var x = new Float16( 5.0 ); + * + * var str = x.toString(); + * // returns '5' + */ + toString(): string; + + /** + * Serializes a half-precision floating-point number as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Float16` instance. + * + * + * @returns serialized half-precision floating-point number + * + * @example + * var x = new Float16( 5.0 ); + * + * var obj = x.toJSON(); + * // returns { 'type': 'Float16', 'value': 5.0 } + */ + toJSON(): any; +} + + +// EXPORTS // + +export = Float16; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts new file mode 100644 index 000000000000..033a41e3c03e --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import Float16 = require( './index' ); + + +// TESTS // + +// The function returns a 64-bit complex number with the expected properties... +{ + const x = new Float16( 5.0 ); // $ExpectType Float16 + + x.value; // $ExpectType number + x.BYTES_PER_ELEMENT; // $ExpectType 2 +} + +// 16-bit half-precision floating-point number comes with a `toString` method to serialize a complex number as a string... +{ + const x = new Float16( 5.0 ); // $ExpectType Float16 + + x.toString(); // $ExpectType string +} + +// 16-bit half-precision floating-point number comes with a `toJSON` method to serialize a complex number as a JSON object.... +{ + const x = new Float16( 5.0 ); // $ExpectType Float16 + + x.toJSON(); // $ExpectType any +} + +// The compiler throws an error if the constructor is invoked without the `new` keyword... +{ + Float16( 5.0 ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided an unsupported number of arguments... +{ + new Float16( ); // $ExpectError + new Float16( 5.0, 3.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js b/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js new file mode 100644 index 000000000000..e8ebf293979d --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Float16 = require( './../lib' ); + +var x = new Float16( 3.14 ); + +console.log( 'type: %s', typeof x ); +// => 'type: object' + +console.log( 'str: %s', x ); +// => 'str: 3.140625' + +console.log( 'value: %d', x.value ); +// => 'value: 3.140625' + +console.log( 'JSON: %s', JSON.stringify( x ) ); +// => 'JSON: {"type":"Float16","value":3.140625}' diff --git a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h index ee7fc62e7e4d..70feb5303f8a 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h +++ b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h @@ -45,86 +45,6 @@ typedef struct { uint16_t bits; } stdlib_float16_t; -/** -* Creates a half-precision floating-point number from a single-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_float32( const float value ); - -/** -* Creates a half-precision floating-point number from a double-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_float64( const double value ); - -/** -* Converts a half-precision floating-point number to single-precision floating-point number. -*/ -float stdlib_float16_to_float32( const stdlib_float16_t value ); - -/** -* Converts a half-precision floating-point number to double-precision floating-point number. -*/ -double stdlib_float16_to_float64( const stdlib_float16_t value ); - -/** -* Converts a signed 8-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_int8( const int8_t value ); - -/** -* Converts an unsigned 8-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ); - -/** -* Converts a signed 16-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_int16( const int16_t value ); - -/** -* Converts an unsigned 16-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ); - -/** -* Converts a signed 32-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_int32( const int32_t value ); - -/** -* Converts an unsigned 32-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ); - -/** -* Converts a signed 64-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_int64( const int64_t value ); - -/** -* Converts an unsigned 64-bit integer to a half-precision floating-point number. -*/ -stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ); - -/** -* Converts a half-precision floating-point number to a signed 32-bit integer. -*/ -int32_t stdlib_float16_to_int32( const stdlib_float16_t value ); - -/** -* Converts a half-precision floating-point number to an unsigned 32-bit integer. -*/ -uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ); - -/** -* Creates a half-precision floating-point number from raw bits. -*/ -stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ); - -/** -* Extracts the raw bit representation from a half-precision floating-point number. -*/ -uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ); - #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/number/float16/ctor/manifest.json b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json index 2f66c1c8e50d..844d692f6439 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/manifest.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json @@ -24,26 +24,13 @@ ], "confs": [ { - "src": [ - "./src/main.c" - ], + "src": [], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [ - "@stdlib/constants/float32/sign-mask", - "@stdlib/constants/float32/exponent-mask", - "@stdlib/constants/float32/significand-mask", - "@stdlib/constants/float32/num-significand-bits", - "@stdlib/constants/float16/sign-mask", - "@stdlib/constants/float16/exponent-mask", - "@stdlib/constants/float16/significand-mask", - "@stdlib/constants/float16/num-significand-bits", - "@stdlib/number/float32/base/exponent", - "@stdlib/math/base/special/exp2" - ] + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/package.json b/lib/node_modules/@stdlib/number/float16/ctor/package.json index 19c43238d2fb..a1d3f5f62017 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/package.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/package.json @@ -20,7 +20,6 @@ "example": "./examples", "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c deleted file mode 100644 index 2bbfdaa7de25..000000000000 --- a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c +++ /dev/null @@ -1,440 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/number/float16/ctor.h" -#include "stdlib/constants/float32/sign_mask.h" -#include "stdlib/constants/float32/exponent_mask.h" -#include "stdlib/constants/float32/significand_mask.h" -#include "stdlib/constants/float32/num_significand_bits.h" -#include "stdlib/constants/float16/sign_mask.h" -#include "stdlib/constants/float16/exponent_mask.h" -#include "stdlib/constants/float16/significand_mask.h" -#include "stdlib/constants/float16/num_significand_bits.h" -#include "stdlib/number/float32/base/exponent.h" -#include -#include - -// VARIABLES // - -static const uint32_t FLOAT32_MAX_EXPONENT = 255; -static const uint32_t FLOAT16_MAX_EXPONENT = 31; -static const uint16_t UINT16_PINF = 0x7C00; // 0x7C00 = 31744 => 0 11111 0000000000 -static const uint16_t UINT16_NINF = 0xFC00; // 0xFC00 = 64512 => 1 11111 0000000000 -static const uint16_t UINT16_NAN = 0x7E00; // 0x7E00 = 32256 => 0 11111 1000000000 -static const uint16_t UINT16_POSITIVE_ZERO = 0x0000; // 0x0000 = 0 => 0 00000 0000000000 -static const uint16_t UINT16_NEGATIVE_ZERO = 0x8000; // 0x8000 = 32768 => 1 00000 0000000000 -static const uint32_t FLOAT32_IMPLICIT_BIT = 0x800000; // 0x800000 = 8388608 => 0 00000001 00000000000000000000000 -static const uint32_t FLOAT32_STICKY_MASK = 0xFFF; // 0xFFF = 4095 => 0 00000000 00000000000111111111111 -static const uint16_t MAX_MANTISSA = 0x3FF; // 0x3FF = 1023 => 0 00000 1111111111 - -/** -* Converts a single-precision floating-point number to a half-precision floating-point number. -* -* @param value single-precision floating-point number -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float32( 5.0f ); -*/ -stdlib_float16_t stdlib_float16_from_float32( const float value ) { - stdlib_float16_t result; - uint32_t f32Mantissa; - uint32_t f32Exponent; - uint32_t f16Mantissa; - uint32_t sticky_bits; - int32_t f16Exponent; - uint32_t round_bit; - uint32_t sign; - uint32_t f32; - int shift; - - // Copy float bits to uint32_t - memcpy( &f32, &value, sizeof(float) ); - - // Extract sign bit and shift to bit 15: - sign = ( f32 & STDLIB_CONSTANT_FLOAT32_SIGN_MASK ) >> 16; - - // Extract exponent bits: - f32Exponent = ( f32 & STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) >> STDLIB_CONSTANT_FLOAT32_NUM_SIGNIFICAND_BITS; - - // Extract mantissa bits: - f32Mantissa = f32 & STDLIB_CONSTANT_FLOAT32_SIGNIFICAND_MASK; - - // Handle special cases... - if ( f32Exponent == FLOAT32_MAX_EXPONENT ) { - if ( f32Mantissa == 0 ) { - if ( sign ) { - result.bits = UINT16_NINF; // -Infinity - } else { - result.bits = UINT16_PINF; // +Infinity - } - } else { - result.bits = UINT16_NAN; // NaN - } - return result; - } - - if ( f32Exponent == 0 && f32Mantissa == 0 ) { - if (sign) { - result.bits = UINT16_NEGATIVE_ZERO; - } else { - result.bits = UINT16_POSITIVE_ZERO; - } - return result; - } - - // Convert exponent from float32 bias (127) to float16 bias (15) - f16Exponent = stdlib_base_float32_exponent( value ) + 15; - - // Handle overflow (infinity in float16)... - if ( f16Exponent >= 31 ) { - if ( sign ) { - result.bits = UINT16_NINF; // -Infinity - } else { - result.bits = UINT16_PINF; // +Infinity - } - return result; - } - - // Handle underflow (subnormal or zero in float16)... - if ( f16Exponent <= 0 ) { - // Check if the value is too small to be represented even as a subnormal float16 number: - if ( f16Exponent < -10 ) { - // Too small, round to zero - if ( sign ) { - result.bits = UINT16_NEGATIVE_ZERO; - } else { - result.bits = UINT16_POSITIVE_ZERO; - } - return result; - } - - // Calculate the amount of right shift needed to denormalize the mantissa for subnormal representation: - shift = 1 - f16Exponent; - - // Create an 11-bit mantissa by adding the implicit leading 1 bit and extracting the top 10 bits from mantissa: - f32Mantissa |= FLOAT32_IMPLICIT_BIT; - f16Mantissa = f32Mantissa >> ( 13 + shift ); - - // Round to nearest, ties to even - round_bit = ( f32Mantissa >> ( 12 + shift ) ) & 1; - sticky_bits = f32Mantissa & ( ( 1u << ( 12 + shift ) ) - 1 ); - - if ( round_bit && ( sticky_bits || ( f16Mantissa & 1 ) ) ) { - f16Mantissa += 1; - } - - result.bits = (uint16_t)(sign | f16Mantissa); - return result; - } - - // Extract the top 10 bits of the mantissa from 23 bits: - f16Mantissa = f32Mantissa >> 13; - - // Extract the round bit (the first bit that will be truncated): - round_bit = ( f32Mantissa >> 12 ) & 1; - - // Check sticky bits (all bits below bit 12): - sticky_bits = f32Mantissa & FLOAT32_STICKY_MASK; - - if ( round_bit && ( sticky_bits || ( f16Mantissa & 1 ) ) ) { - f16Mantissa += 1; - - // Check for mantissa overflow (carries into exponent)... - if ( f16Mantissa > MAX_MANTISSA ) { - f16Exponent += 1; - f16Mantissa = 0; - - // Check for exponent overflow... - if ( f16Exponent >= 31 ) { - if ( sign ) { - result.bits = UINT16_NINF; // -Infinity - } else { - result.bits = UINT16_PINF; // +Infinity - } - return result; - } - } - } - - // Combine sign (1 bit), exponent (5 bits), and mantissa (10 bits): - result.bits = (uint16_t)(sign | (f16Exponent << 10) | f16Mantissa); - return result; -} - -/** -* Converts a double-precision floating-point number to a half-precision floating-point number. -* -* @param value double-precision floating-point number -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float64( 5.0 ); -*/ -stdlib_float16_t stdlib_float16_from_float64( const double value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts a half-precision floating-point number to a single-precision floating-point number. -* -* @param value half-precision floating-point number -* @return single-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float32( 2.5f ); -* float y = stdlib_float16_to_float32( x ); -*/ -float stdlib_float16_to_float32( const stdlib_float16_t value ) { - uint32_t f32Exponent; - uint32_t f16Mantissa; - uint32_t f16Exponent; - uint32_t sign; - uint32_t f32; - uint16_t f16; - float result; - - f16 = value.bits; - - // Extract sign bit and shift left 16 bits: - sign = ((uint32_t)(f16 & STDLIB_CONSTANT_FLOAT16_SIGN_MASK)) << 16; - - // Extract exponent bits: - f16Exponent = (f16 & STDLIB_CONSTANT_FLOAT16_EXPONENT_MASK) >> STDLIB_CONSTANT_FLOAT16_NUM_SIGNIFICAND_BITS; - - // Extract mantissa bits: - f16Mantissa = f16 & STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK; - - // Handle special cases... - if ( f16Exponent == 0 ) { - if ( f16Mantissa == 0 ) { - // Zero - f32 = sign; - memcpy( &result, &f32, sizeof(float) ); - return result; - } - - // Denormalized number - convert to normalized float32 - f32Exponent = 1; - while ( ( f16Mantissa & 0x0400 ) == 0 ) { - f16Mantissa <<= 1; - f32Exponent -= 1; - } - - f16Mantissa &= STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK; - f32Exponent = 127 - 15 + f32Exponent; - f32 = sign | (f32Exponent << 23) | (f16Mantissa << 13); - memcpy( &result, &f32, sizeof(float) ); - return result; - } - - if (f16Exponent == FLOAT16_MAX_EXPONENT) { - // Infinity or NaN - f32 = sign | STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK | (f16Mantissa << 13); - memcpy( &result, &f32, sizeof(float) ); - return result; - } - - // Normal case: convert exponent from float16 bias (15) to float32 bias (127) - f32Exponent = f16Exponent - 15 + 127; - f32 = sign | (f32Exponent << 23) | (f16Mantissa << 13); - memcpy( &result, &f32, sizeof(float) ); - return result; -} - -/** -* Converts a half-precision floating-point number to a double-precision floating-point number. -* -* @param value half-precision floating-point number -* @return double-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float64( 2.5 ); -* double y = stdlib_float16_to_float64( x ); -*/ -double stdlib_float16_to_float64( const stdlib_float16_t value ) { - return (double)stdlib_float16_to_float32( value ); -} - -/** -* Converts a signed 8-bit integer to half-precision floating-point number. -* -* @param value signed 8-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_int8( 42 ); -*/ -stdlib_float16_t stdlib_float16_from_int8( const int8_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts an unsigned 8-bit integer to half-precision floating-point number. -* -* @param value unsigned 8-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_uint8( 200 ); -*/ -stdlib_float16_t stdlib_float16_from_uint8( const uint8_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts a signed 16-bit integer to half-precision floating-point number. -* -* @param value signed 16-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_int16( 1000 ); -*/ -stdlib_float16_t stdlib_float16_from_int16( const int16_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts an unsigned 16-bit integer to half-precision floating-point number. -* -* @param value unsigned 16-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_uint16( 50000 ); -*/ -stdlib_float16_t stdlib_float16_from_uint16( const uint16_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts a signed 32-bit integer to half-precision floating-point number. -* -* @param value signed 32-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_int32( 100000 ); -*/ -stdlib_float16_t stdlib_float16_from_int32( const int32_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts an unsigned 32-bit integer to half-precision floating-point number. -* -* @param value unsigned 32-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_uint32( 100000U ); -*/ -stdlib_float16_t stdlib_float16_from_uint32( const uint32_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts a signed 64-bit integer to half-precision floating-point number. -* -* @param value signed 64-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_int64( 1000000LL ); -*/ -stdlib_float16_t stdlib_float16_from_int64( const int64_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts an unsigned 64-bit integer to half-precision floating-point number. -* -* @param value unsigned 64-bit integer -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_uint64( 1000000ULL ); -*/ -stdlib_float16_t stdlib_float16_from_uint64( const uint64_t value ) { - return stdlib_float16_from_float32( (float)value ); -} - -/** -* Converts a half-precision floating-point number to a signed 32-bit integer. -* -* @param value half-precision floating-point number -* @return signed 32-bit integer (truncated toward zero) -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); -* int32_t y = stdlib_float16_to_int32( x ); -*/ -int32_t stdlib_float16_to_int32( const stdlib_float16_t value ) { - return (int32_t)stdlib_float16_to_float32( value ); -} - -/** -* Converts a half-precision floating-point number to an unsigned 32-bit integer. -* -* @param value half-precision floating-point number -* @return unsigned 32-bit integer (truncated toward zero) -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float32( 2.9f ); -* uint32_t y = stdlib_float16_to_uint32( x ); -*/ -uint32_t stdlib_float16_to_uint32( const stdlib_float16_t value ) { - float f = stdlib_float16_to_float32( value ); - if (f < 0.0f) { - return 0; - } - return (uint32_t)f; -} - -/** -* Creates a half-precision floating-point number from raw bits. -* -* @param bits raw IEEE 754 binary16 bit pattern -* @return half-precision floating-point number -* -* @example -* stdlib_float16_t x = stdlib_float16_from_bits( 0x4000 ); -* float y = stdlib_float16_to_float32( x ); -* // returns 2.0f -*/ -stdlib_float16_t stdlib_float16_from_bits( const uint16_t bits ) { - stdlib_float16_t result; - result.bits = bits; - return result; -} - -/** -* Extracts the raw bit representation from a half-precision floating-point number. -* -* @param value half-precision floating-point number -* @return raw IEEE 754 binary16 bit pattern -* -* @example -* stdlib_float16_t x = stdlib_float16_from_float32( 2.0f ); -* uint16_t bits = stdlib_float16_to_bits( x ); -* // returns 0x4000 -*/ -uint16_t stdlib_float16_to_bits( const stdlib_float16_t value ) { - return value.bits; -} From fdc77bc010861b996b74e84030cbe54a92108934 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 8 Dec 2025 18:17:04 +0000 Subject: [PATCH 3/9] chore: update copyright years --- lib/node_modules/@stdlib/number/float16/ctor/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js b/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js index e8ebf293979d..649e98d74215 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From dad8b167022f3436e8ec0285e51dd412c4a21e3f Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 9 Dec 2025 03:13:02 +0530 Subject: [PATCH 4/9] fix: resolve errors --- 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: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 --- --- lib/node_modules/@stdlib/number/float16/ctor/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/ctor/package.json b/lib/node_modules/@stdlib/number/float16/ctor/package.json index a1d3f5f62017..3532f8a6ae62 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/package.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/package.json @@ -15,7 +15,6 @@ ], "main": "./lib", "directories": { - "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "include": "./include", From e7992c80a09ba3f50e3e38a98f0da36d900a49eb Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 18 Dec 2025 18:12:08 +0530 Subject: [PATCH 5/9] feat: add valueOf and Symbol.toPrimitive methods to Float16; update documentation --- 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: na - task: lint_repl_help status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../@stdlib/number/float16/ctor/README.md | 41 +++++++++++- .../@stdlib/number/float16/ctor/docs/repl.txt | 10 +-- .../number/float16/ctor/docs/types/index.d.ts | 23 +++++-- .../number/float16/ctor/docs/types/test.ts | 6 +- .../ctor/include/stdlib/number/float16/ctor.h | 4 +- .../@stdlib/number/float16/ctor/lib/main.js | 62 ++++++++++++++----- .../@stdlib/number/float16/ctor/lib/tojson.js | 3 +- .../number/float16/ctor/lib/tostring.js | 3 +- .../number/float16/ctor/lib/valueof.js | 34 ++++++++++ .../@stdlib/number/float16/ctor/test/test.js | 55 +++++++++++++++- 10 files changed, 201 insertions(+), 40 deletions(-) create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js diff --git a/lib/node_modules/@stdlib/number/float16/ctor/README.md b/lib/node_modules/@stdlib/number/float16/ctor/README.md index ee1f751b8d00..d8370273c925 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/README.md +++ b/lib/node_modules/@stdlib/number/float16/ctor/README.md @@ -55,7 +55,7 @@ var x = new Float16( 5.0 ); #### Float16.BYTES_PER_ELEMENT -Size (in bytes) of each component. +Size (in bytes) of the underlying value. ```javascript var nbytes = Float16.BYTES_PER_ELEMENT; @@ -64,7 +64,7 @@ var nbytes = Float16.BYTES_PER_ELEMENT; #### Float16.prototype.BYTES_PER_ELEMENT -Size (in bytes) of each component. +Size (in bytes) of the underlying value. ```javascript var x = new Float16( 5.0 ); @@ -128,6 +128,42 @@ var o = x.toJSON(); To [revive][mdn-json-parse] a `Float16` number from a [JSON][json] `string`, see [@stdlib/number/float16/reviver][@stdlib/number/float16/reviver]. +#### Float16.prototype.valueOf() + +Returns the primitive `number` value of a `Float16` instance. + +```javascript +var x = new Float16( 5.0 ); +var v = x.valueOf(); +// returns 5.0 + +x = new Float16( 3.14 ); +v = x.valueOf(); +// returns 3.140625 +``` + +#### Float16.prototype\[ Symbol.toPrimitive ]() + +Returns the primitive value of a `Float16` instance when JavaScript attempts to convert the object to a primitive (`number`, `string`, or `default`). This method enables implicit type coercion in arithmetic and other operations. + +```javascript +var x = new Float16( 5.0 ); + +// Explicit invocation: +var v = x[ Symbol.toPrimitive ]( 'number' ); +// returns 5.0 + +// Implicit coercion in arithmetic: +var y = x + 5; +// returns 10.0 + +// Between two Float16 instances: +var a = new Float16( 3.0 ); +var b = new Float16( 2.0 ); +var s = a + b; +// returns 5.0 +``` + @@ -142,7 +178,6 @@ To [revive][mdn-json-parse] a `Float16` number from a [JSON][json] `string`, see - The float16 value is stored as a half-precision floating-point format [IEEE 754][ieee754] with 1 sign bit, 5 exponent bits, and 10 significand bits. - Float16 has a range of approximately `±6.55e4` and precision of about 3-4 decimal digits. -- This is a **storage-only** type. All arithmetic operations should be performed by converting to `float32` or `float64`, computing, and converting back. diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt index 3ec1137f3aed..3a4ab7e4d084 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( value ) 16-bit half-precision floating-point number constructor. - Value component is stored as half-precision floating-point numbers. + Value property stores the half-precision floating-point numbers. Parameters ---------- @@ -23,12 +23,12 @@ {{alias}}.BYTES_PER_ELEMENT - Size (in bytes) of each component. + Size (in bytes) of the underlying value. Returns ------- v: integer - Size (in bytes) of each component. + Size (in bytes) of the underlying value.. Examples -------- @@ -37,12 +37,12 @@ {{alias}}.prototype.BYTES_PER_ELEMENT - Size (in bytes) of each component. + Size (in bytes) of the underlying value.. Returns ------- s: integer - Size (in bytes) of each component. + Size (in bytes) of the underlying value.. Examples -------- diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts index 2e5ed0c542d2..960747e5b009 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts @@ -23,7 +23,7 @@ */ declare class Float16 { /** - * 64-bit half-precision floating-point number constructor. + * 16-bit half-precision floating-point number constructor. * * @param value - numeric value * @returns 16-bit half-precision floating-point number @@ -35,16 +35,16 @@ declare class Float16 { constructor( value: number ); /** - * Read-only property returning the value component. + * Read-only property returning the value. * - * @returns value component + * @returns value */ readonly value: number; /** - * Size (in bytes) of each component. + * Size (in bytes) of the underlying value. * - * @returns size of each component + * @returns size of the underlying value. * * @example * var nbytes = Float16.BYTES_PER_ELEMENT; @@ -82,6 +82,19 @@ declare class Float16 { * // returns { 'type': 'Float16', 'value': 5.0 } */ toJSON(): any; + + /** + * Returns the primitive value of a half-precision floating-point number. + * + * @returns primitive value + * + * @example + * var x = new Float16( 5.0 ); + * + * var v = x.valueOf(); + * // returns 5.0 + */ + valueOf(): number; } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts index 033a41e3c03e..eaf6bf1da988 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts @@ -23,7 +23,7 @@ import Float16 = require( './index' ); // TESTS // -// The function returns a 64-bit complex number with the expected properties... +// The function returns a 16-bit half-precision floating-point number with the expected properties... { const x = new Float16( 5.0 ); // $ExpectType Float16 @@ -31,14 +31,14 @@ import Float16 = require( './index' ); x.BYTES_PER_ELEMENT; // $ExpectType 2 } -// 16-bit half-precision floating-point number comes with a `toString` method to serialize a complex number as a string... +// 16-bit half-precision floating-point number comes with a `toString` method to serialize a number as a string... { const x = new Float16( 5.0 ); // $ExpectType Float16 x.toString(); // $ExpectType string } -// 16-bit half-precision floating-point number comes with a `toJSON` method to serialize a complex number as a JSON object.... +// 16-bit half-precision floating-point number comes with a `toJSON` method to serialize a number as a JSON object.... { const x = new Float16( 5.0 ); // $ExpectType Float16 diff --git a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h index 70feb5303f8a..b56b8d5ca1e4 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h +++ b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h @@ -20,7 +20,6 @@ #define STDLIB_NUMBER_FLOAT16_CTOR_H #include -#include /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -33,6 +32,9 @@ extern "C" { * An opaque type definition for a half-precision floating-point number. * * @example +* #include "stdlib/number/float32/base/to_float16.h" +* #include "stdlib/number/float16/base/to_float32.h" +* * stdlib_float16_t x = stdlib_float16_from_float32( 3.14f ); * * float y = stdlib_float16_to_float32( x ); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js index 399e1d72d992..6a45a0aa32f3 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js @@ -25,8 +25,11 @@ var defineProperty = require( '@stdlib/utils/define-property' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); var format = require( '@stdlib/string/format' ); +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +var ToPrimitiveSymbol = require( '@stdlib/symbol/to-primitive' ); var toStr = require( './tostring.js' ); var toJSON = require( './tojson.js' ); +var valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare // MAIN // @@ -49,36 +52,26 @@ function Float16( value ) { throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' ); } if ( !isNumber( value ) ) { - throw new TypeError( format( 'invalid argument. Value must be a number. Value: `%s`.', value ) ); + throw new TypeError( format( 'invalid argument. Must provide a number. Value: `%s`.', value ) ); } - // Store as uint16 bits (internal representation) - defineProperty( this, '_bits', { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': float64ToFloat16( value ) - }); - - // Define read-only value property that converts back to number defineProperty( this, 'value', { 'configurable': false, 'enumerable': true, - 'get': function getValue() { // eslint-disable-line no-restricted-syntax - return this._bits; - } + 'writable': false, + 'value': float64ToFloat16( value ) }); return this; } /** -* Size (in bytes) of each component. +* Size (in bytes) of the underlying value. * * @name BYTES_PER_ELEMENT * @memberof Float16 * @type {integer} -* @returns {integer} size of each component +* @returns {integer} size in bytes * * @example * var nbytes = Float16.BYTES_PER_ELEMENT; @@ -87,12 +80,12 @@ function Float16( value ) { setReadOnly( Float16, 'BYTES_PER_ELEMENT', 2 ); /** -* Size (in bytes) of each component. +* Size (in bytes) of the underlying value. * * @name BYTES_PER_ELEMENT * @memberof Float16.prototype * @type {integer} -* @returns {integer} size of each component +* @returns {integer} size in bytes * * @example * var x = new Float16( 5.0 ); @@ -138,6 +131,41 @@ setReadOnly( Float16.prototype, 'toString', toStr ); */ setReadOnly( Float16.prototype, 'toJSON', toJSON ); +/** +* Returns the primitive value of a half-precision floating-point number. +* +* @name valueOf +* @memberof Float16.prototype +* @type {Function} +* @returns {number} primitive value +* +* @example +* var x = new Float16( 5.0 ); +* +* var v = x.valueOf(); +* // returns 5.0 +*/ +setReadOnly( Float16.prototype, 'valueOf', valueOf ); + +/** +* Returns the primitive value of a half-precision floating-point number. +* +* @name toPrimitive +* @memberof Float16.prototype +* @type {Function} +* @param {string} hint - conversion hint +* @returns {number} primitive value +* +* @example +* var x = new Float16( 5.0 ); +* +* var v = x[ Symbol.toPrimitive ]( 'number' ); +* // returns 5.0 +*/ +if ( hasToPrimitiveSymbolSupport ) { + setReadOnly( Float16.prototype, ToPrimitiveSymbol, valueOf); +} + // EXPORTS // diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js index 3102401bd201..49f01d7e83ca 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/tojson.js @@ -25,10 +25,9 @@ * @returns {Object} JSON representation */ function toJSON() { - /* eslint-disable no-invalid-this */ var out = {}; out.type = 'Float16'; - out.value = this.value; + out.value = this.value; // eslint-disable-line no-invalid-this return out; } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js index ae5575b11644..f3befccb3048 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js @@ -25,8 +25,7 @@ * @returns {string} serialized half-precision floating-point number */ function toString() { // eslint-disable-line stdlib/no-redeclare - /* eslint-disable no-invalid-this */ - return '' + this.value; + return '' + this.value; // eslint-disable-line no-invalid-this } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js new file mode 100644 index 000000000000..0201d1d32849 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the primitive value of a half-precision floating-point number. +* +* @private +* @returns {number} primitive value +*/ +function valueOf() { // eslint-disable-line stdlib/no-redeclare + return this.value; // eslint-disable-line no-invalid-this +} + + +// EXPORTS // + +module.exports = valueOf; diff --git a/lib/node_modules/@stdlib/number/float16/ctor/test/test.js b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js index a8c505b2f161..1d201a8ae830 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/test/test.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); var Float16 = require( './../lib' ); @@ -39,7 +40,7 @@ tape( 'the function is a constructor', function test( t ) { t.end(); }); -tape( 'the constructor throws an error if provided a value component which is not a number', function test( t ) { +tape( 'the constructor throws an error if provided a value property which is not a number', function test( t ) { var values; var i; @@ -113,7 +114,7 @@ tape( 'the constructor returns an instance which throws an error when attempting } }); -tape( 'the constructor returns an instance which stores value component as half-precision floating-point numbers', function test( t ) { +tape( 'the constructor returns an instance which stores value property as half-precision floating-point numbers', function test( t ) { var x = new Float16( 3.14 ); t.strictEqual( x.value, 3.140625, 'stores as half-precision' ); @@ -155,3 +156,53 @@ tape( 'the constructor returns an instance which supports serializing an instanc t.end(); }); + +tape( 'the constructor returns an instance which supports getting the primitive value', function test( t ) { + var x; + + x = new Float16( 5.0 ); + t.strictEqual( typeof x.valueOf, 'function', 'has valueOf method' ); + t.strictEqual( x.valueOf(), 5.0, 'returns expected value' ); + + x = new Float16( -5.0 ); + t.strictEqual( x.valueOf(), -5.0, 'returns expected value' ); + + x = new Float16( 3.14 ); + t.strictEqual( x.valueOf(), 3.140625, 'returns half-precision value' ); + + x = new Float16( 0.0 ); + t.strictEqual( x.valueOf(), 0.0, 'returns zero' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports type coercion via Symbol.toPrimitive (if supported)', function test( t ) { + var x; + var y; + + if ( !hasToPrimitiveSymbolSupport() ) { + t.ok( true, 'environment does not support Symbol.toPrimitive' ); + t.end(); + return; + } + x = new Float16( 5.0 ); + + t.strictEqual( typeof x[ Symbol.toPrimitive ], 'function', 'has Symbol.toPrimitive method' ); + t.strictEqual( x[ Symbol.toPrimitive ]( 'number' ), 5.0, 'returns expected value for number hint' ); + t.strictEqual( x[ Symbol.toPrimitive ]( 'default' ), 5.0, 'returns expected value for default hint' ); + t.strictEqual( x[ Symbol.toPrimitive ]( 'string' ), 5.0, 'returns expected value for string hint' ); + + x = new Float16( -3.14 ); + t.strictEqual( x[ Symbol.toPrimitive ](), -3.140625, 'returns half-precision value' ); + + // Test implicit type coercion: + x = new Float16( 10.0 ); + t.strictEqual( x + 5, 15.0, 'supports addition via type coercion' ); + t.strictEqual( x * 2, 20.0, 'supports multiplication via type coercion' ); + + x = new Float16( 3.0 ); + y = new Float16( 2.0 ); + t.strictEqual( x + y, 5.0, 'supports addition between two Float16 instances' ); + + t.end(); +}); From 2d0d067aea99efd8dce64bc022d0d7075acd04c5 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 18 Dec 2025 16:12:00 -0800 Subject: [PATCH 6/9] style: add missing space Signed-off-by: Athan --- lib/node_modules/@stdlib/number/float16/ctor/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js index 6a45a0aa32f3..181a1bca8357 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js @@ -163,7 +163,7 @@ setReadOnly( Float16.prototype, 'valueOf', valueOf ); * // returns 5.0 */ if ( hasToPrimitiveSymbolSupport ) { - setReadOnly( Float16.prototype, ToPrimitiveSymbol, valueOf); + setReadOnly( Float16.prototype, ToPrimitiveSymbol, valueOf ); } From 32ee452da92bbe37b5d4142d254adc074b548af1 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 18 Dec 2025 23:41:12 -0800 Subject: [PATCH 7/9] refactor: add C helpers, benchmarks, and examples --- 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: na - 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: na - 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 --- --- .../@stdlib/number/float16/ctor/README.md | 125 +++++++++++---- .../float16/ctor/benchmark/benchmark.js | 116 ++++++++++++++ .../@stdlib/number/float16/ctor/docs/repl.txt | 24 ++- .../number/float16/ctor/docs/types/index.d.ts | 4 +- .../number/float16/ctor/docs/types/test.ts | 7 + .../number/float16/ctor/examples/c/Makefile | 146 ++++++++++++++++++ .../number/float16/ctor/examples/c/example.c | 33 ++++ .../ctor/include/stdlib/number/float16/ctor.h | 58 ++++++- .../@stdlib/number/float16/ctor/lib/main.js | 42 +++-- .../number/float16/ctor/lib/tostring.js | 2 +- .../number/float16/ctor/lib/valueof.js | 2 +- .../@stdlib/number/float16/ctor/manifest.json | 4 +- .../@stdlib/number/float16/ctor/package.json | 1 + .../@stdlib/number/float16/ctor/src/main.c | 45 ++++++ .../@stdlib/number/float16/ctor/test/test.js | 69 +++++---- 15 files changed, 589 insertions(+), 89 deletions(-) create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/number/float16/ctor/src/main.c diff --git a/lib/node_modules/@stdlib/number/float16/ctor/README.md b/lib/node_modules/@stdlib/number/float16/ctor/README.md index d8370273c925..56ef1ab0798d 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/README.md +++ b/lib/node_modules/@stdlib/number/float16/ctor/README.md @@ -53,6 +53,15 @@ var x = new Float16( 5.0 ); ## Properties +#### Float16.name + +Static property returning the constructor name. + +```javascript +var str = Float16.name; +// returns 'Float16' +``` + #### Float16.BYTES_PER_ELEMENT Size (in bytes) of the underlying value. @@ -79,7 +88,7 @@ A `Float16` instance has the following properties... #### value -A **read-only** property returning the float16 value as a `number`. +A **read-only** property returning the underlying value as a number. ```javascript var x = new Float16( 5.0 ); @@ -94,11 +103,11 @@ var v = x.value; ### Accessor Methods -These methods do **not** mutate a `Float16` instance and, instead return the float16 representation. +These methods do **not** mutate a `Float16` instance and, instead return a half-precision floating-point number representation. #### Float16.prototype.toString() -Returns a `string` representation of a `Float16` instance. +Returns a string representation of a `Float16` instance. ```javascript var x = new Float16( 5.0 ); @@ -130,7 +139,7 @@ To [revive][mdn-json-parse] a `Float16` number from a [JSON][json] `string`, see #### Float16.prototype.valueOf() -Returns the primitive `number` value of a `Float16` instance. +Converts a `Float16` instance to a primitive value. ```javascript var x = new Float16( 5.0 ); @@ -142,28 +151,6 @@ v = x.valueOf(); // returns 3.140625 ``` -#### Float16.prototype\[ Symbol.toPrimitive ]() - -Returns the primitive value of a `Float16` instance when JavaScript attempts to convert the object to a primitive (`number`, `string`, or `default`). This method enables implicit type coercion in arithmetic and other operations. - -```javascript -var x = new Float16( 5.0 ); - -// Explicit invocation: -var v = x[ Symbol.toPrimitive ]( 'number' ); -// returns 5.0 - -// Implicit coercion in arithmetic: -var y = x + 5; -// returns 10.0 - -// Between two Float16 instances: -var a = new Float16( 3.0 ); -var b = new Float16( 2.0 ); -var s = a + b; -// returns 5.0 -``` - @@ -176,8 +163,8 @@ var s = a + b; ## Notes -- The float16 value is stored as a half-precision floating-point format [IEEE 754][ieee754] with 1 sign bit, 5 exponent bits, and 10 significand bits. -- Float16 has a range of approximately `±6.55e4` and precision of about 3-4 decimal digits. +- The underlying value is stored as a half-precision floating-point number [IEEE 754][ieee754] with 1 sign bit, 5 exponent bits, and 10 significand bits. +- A half-precision floating-point number has a range of approximately `±6.55e4` and a precision of about 3-4 decimal digits. @@ -246,14 +233,60 @@ console.log( 'JSON: %s', JSON.stringify( x ) ); An opaque type definition for a half-precision floating-point number. ```c -typedef struct { - /** - * Raw IEEE 754 binary16 bit representation. - */ - uint16_t bits; -} stdlib_float16_t; +stdlib_float16_t v = stdlib_float16_from_bits( 51648 ); ``` +#### stdlib_float16_bits_t + +An opaque type definition for a union for accessing the underlying binary representation of a half-precision floating-point number. + +```c +#include + +stdlib_float16_t x = stdlib_float16_from_bits( 51648 ); + +stdlib_float16_bits_t y; +y.value = x; + +uint16_t bits = y.bits; +// returns 51648 +``` + +The union has the following members: + +- **value**: `stdlib_float16_t` half-precision floating-point number. +- **bits**: `uint16_t` binary representation. + +The union allows "type punning"; however, while (more or less) defined in C99, behavior is implementation-defined in C++. For more robust conversion, prefer using explicit helpers for converting to and from binary representation. + +#### stdlib_float16_from_bits( bits ) + +Converts a 16-bit binary representation to a half-precision floating-point number. + +```c +stdlib_float16_t v = stdlib_float16_from_bits( 51648 ); // => -11.5 +``` + +The function accepts the following arguments: + +- **bits**: `[in] uint16_t` 16-bit integer corresponding to a binary representation. + +#### stdlib_float16_to_bits( x ) + +Converts a half-precision floating-point number to a 16-bit binary representation. + +```c +#include + +stdlib_float16_t v = stdlib_float16_from_bits( 51648 ); // => -11.5 + +uint16_t bits = stdlib_float16_to_bits( v ); +``` + +The function accepts the following arguments: + +- **x**: `[in] stdlib_float16_t` half-precision floating-point number. + @@ -262,6 +295,10 @@ typedef struct {
+### Notes + +- The `stdlib_float16_t` type should be treated as a storage and interchange type. Native hardware support for mathematical functions operating on half-precision floating-point numbers varies. As a consequence, for most operations, one should first promote to single-precision (i.e., `float`), perform the desired operation, and then downcast back to half-precision. +
@@ -270,6 +307,26 @@ typedef struct {
+### Examples + +```c +#include "stdlib/number/float16/ctor.h" +#include +#include + +int main( void ) { + const stdlib_float16_t x[] = { + stdlib_float16_from_bits( 51648 ), // -11.5 + stdlib_float16_from_bits( 18880 ) // 11.5 + }; + + int i; + for ( i = 0; i < 2; i++ ) { + printf( "%d\n", stdlib_float16_to_bits( x[ i ] ) ); + } +} +``` +
diff --git a/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js new file mode 100644 index 000000000000..ed1265e901c0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/benchmark/benchmark.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16 = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = new Float16( i, i ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !( z instanceof Float16 ) ) { + b.fail( 'should return a complex number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:value', pkg ), function benchmark( b ) { + var v; + var z; + var i; + + z = new Float16( randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = z.value; + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:toString', pkg ), function benchmark( b ) { + var o; + var z; + var i; + + z = new Float16( randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toString(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:toJSON', pkg ), function benchmark( b ) { + var o; + var z; + var i; + + z = new Float16( randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toJSON(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt index 3a4ab7e4d084..69b082d5f0c8 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/repl.txt @@ -2,8 +2,6 @@ {{alias}}( value ) 16-bit half-precision floating-point number constructor. - Value property stores the half-precision floating-point numbers. - Parameters ---------- value: number @@ -11,9 +9,12 @@ Returns ------- - x : number + v: Float16 Half-precision floating-point number. + v.value: number + Read-only property returning the underlying value. + Examples -------- > var x = new {{alias}}( 3.14 ) @@ -22,13 +23,22 @@ 3.140625 +{{alias}}.name + Constructor name. + + Examples + -------- + > var str = {{alias}}.name + 'Float16' + + {{alias}}.BYTES_PER_ELEMENT Size (in bytes) of the underlying value. Returns ------- - v: integer - Size (in bytes) of the underlying value.. + s: integer + Size (in bytes) of the underlying value. Examples -------- @@ -37,12 +47,12 @@ {{alias}}.prototype.BYTES_PER_ELEMENT - Size (in bytes) of the underlying value.. + Size (in bytes) of the underlying value. Returns ------- s: integer - Size (in bytes) of the underlying value.. + Size (in bytes) of the underlying value. Examples -------- diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts index 960747e5b009..c674712de312 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/index.d.ts @@ -26,7 +26,7 @@ declare class Float16 { * 16-bit half-precision floating-point number constructor. * * @param value - numeric value - * @returns 16-bit half-precision floating-point number + * @returns half-precision floating-point number * * @example * var x = new Float16( 5.0 ); @@ -84,7 +84,7 @@ declare class Float16 { toJSON(): any; /** - * Returns the primitive value of a half-precision floating-point number. + * Converts a half-precision floating-point number to a primitive value. * * @returns primitive value * diff --git a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts index eaf6bf1da988..c836c2d9a3fa 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts +++ b/lib/node_modules/@stdlib/number/float16/ctor/docs/types/test.ts @@ -45,6 +45,13 @@ import Float16 = require( './index' ); x.toJSON(); // $ExpectType any } +// 16-bit half-precision floating-point number comes with a `valueOf` method to serialize a number to a primitive value... +{ + const x = new Float16( 5.0 ); // $ExpectType Float16 + + x.valueOf(); // $ExpectType number +} + // The compiler throws an error if the constructor is invoked without the `new` keyword... { Float16( 5.0 ); // $ExpectError diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile new file mode 100644 index 000000000000..70c91f4e1313 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2021 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c new file mode 100644 index 000000000000..b3749106a469 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/number/float16/ctor.h" +#include +#include + +int main( void ) { + const stdlib_float16_t x[] = { + stdlib_float16_from_bits( 51648 ), // -11.5 + stdlib_float16_from_bits( 18880 ) // 11.5 + }; + + int i; + for ( i = 0; i < 2; i++ ) { + printf( "%d\n", stdlib_float16_to_bits( x[ i ] ) ); + } +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h index b56b8d5ca1e4..c4905add04b4 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h +++ b/lib/node_modules/@stdlib/number/float16/ctor/include/stdlib/number/float16/ctor.h @@ -28,6 +28,35 @@ extern "C" { #endif +// Check for native Float16 support... + +// First check the language standard first, as `_Float16` was standardized in C23... +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L + +/** +* An opaque type definition for a half-precision floating-point number. +*/ +typedef _Float16 stdlib_float16_t; + +// If the previous check failed, check for the GCC/Clang `_Float16` extension... +#elif defined(__FLT16_MANT_DIG__) + +/** +* An opaque type definition for a half-precision floating-point number. +*/ +typedef _Float16 stdlib_float16_t; + +// If the previous check failed, check for Clang support... +#elif defined(__clang__) && (defined(__has_extension) || defined(__has_feature)) && (__has_extension(c_float16) || __has_feature(c_float16)) + +/** +* An opaque type definition for a half-precision floating-point number. +*/ +typedef _Float16 stdlib_float16_t; + +// Otherwise, if we aren't going to use the native half-precision floating-point number type, we need to define a half-precision floating-point number as an "opaque" struct (here, "opaque" means type consumers should **not** be operating with the value directly, but only through dedicated functions) for storing the number value... +#else + /** * An opaque type definition for a half-precision floating-point number. * @@ -42,13 +71,40 @@ extern "C" { */ typedef struct { /** - * Raw IEEE 754 binary16 bit representation. + * Raw IEEE 754 binary representation. */ uint16_t bits; } stdlib_float16_t; +/** +* An opaque type definition for a union for accessing the underlying binary representation of a half-precision floating-point number. +* +* ## Notes +* +* - The union allows "type punning"; however, while (more or less) defined in C99, behavior is implementation-defined in C++. For more robust conversion, prefer using explicit helpers for converting to and from binary representation. +*/ +typedef union { + // An opaque type for the output value (e.g., could be a `struct` or a native half-precision floating-point number): + stdlib_float16_t value; + + // Raw IEEE 754 binary representation. + uint16_t bits; +} stdlib_float16_bits_t; + +#endif + #ifdef __cplusplus } #endif +/** +* Converts a half-precision floating-point number to its binary representation. +*/ +uint16_t stdlib_float16_to_bits( stdlib_float16_t x ); + +/** +* Converts a 16-bit binary representation to a half-precision floating-point number. +*/ +stdlib_float16_t stdlib_float16_from_bits( uint16_t bits ); + #endif // !STDLIB_NUMBER_FLOAT16_CTOR_H diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js index 181a1bca8357..cf44b6b23c6e 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/main.js @@ -21,11 +21,11 @@ // MODULES // var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; -var defineProperty = require( '@stdlib/utils/define-property' ); +var setEnumerableReadOnly = require( '@stdlib/utils/define-read-only-property' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); var format = require( '@stdlib/string/format' ); -var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); // eslint-disable-line id-length var ToPrimitiveSymbol = require( '@stdlib/symbol/to-primitive' ); var toStr = require( './tostring.js' ); var toJSON = require( './tojson.js' ); @@ -54,17 +54,25 @@ function Float16( value ) { if ( !isNumber( value ) ) { throw new TypeError( format( 'invalid argument. Must provide a number. Value: `%s`.', value ) ); } - - defineProperty( this, 'value', { - 'configurable': false, - 'enumerable': true, - 'writable': false, - 'value': float64ToFloat16( value ) - }); - + setEnumerableReadOnly( this, 'value', float64ToFloat16( value ) ); return this; } +/** +* Constructor name. +* +* @name name +* @memberof Float16 +* @readonly +* @type {string} +* @default 'Float16' +* +* @example +* var name = Float16.name; +* // returns 'Float16' +*/ +setReadOnly( Float16, 'name', 'Float16' ); + /** * Size (in bytes) of the underlying value. * @@ -132,7 +140,7 @@ setReadOnly( Float16.prototype, 'toString', toStr ); setReadOnly( Float16.prototype, 'toJSON', toJSON ); /** -* Returns the primitive value of a half-precision floating-point number. +* Converts a half-precision floating-point number to a primitive value. * * @name valueOf * @memberof Float16.prototype @@ -157,12 +165,18 @@ setReadOnly( Float16.prototype, 'valueOf', valueOf ); * @returns {number} primitive value * * @example +* var hasSymbol = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +* var ToPrimitiveSymbol = require( '@stdlib/symbol/to-primitive' ); +* * var x = new Float16( 5.0 ); * -* var v = x[ Symbol.toPrimitive ]( 'number' ); -* // returns 5.0 +* var v; +* if ( hasSymbol() ) { +* v = x[ ToPrimitiveSymbol ]( 'number' ); +* // returns 5.0 +* } */ -if ( hasToPrimitiveSymbolSupport ) { +if ( hasToPrimitiveSymbolSupport() ) { setReadOnly( Float16.prototype, ToPrimitiveSymbol, valueOf ); } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js index f3befccb3048..96cca94da401 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/tostring.js @@ -25,7 +25,7 @@ * @returns {string} serialized half-precision floating-point number */ function toString() { // eslint-disable-line stdlib/no-redeclare - return '' + this.value; // eslint-disable-line no-invalid-this + return String( this.value ); // eslint-disable-line no-invalid-this } diff --git a/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js b/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js index 0201d1d32849..c3e4742b6e64 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/lib/valueof.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Returns the primitive value of a half-precision floating-point number. +* Converts a half-precision floating-point number to a primitive value. * * @private * @returns {number} primitive value diff --git a/lib/node_modules/@stdlib/number/float16/ctor/manifest.json b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json index 844d692f6439..04e61e361caa 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/manifest.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/manifest.json @@ -24,7 +24,9 @@ ], "confs": [ { - "src": [], + "src": [ + "./src/main.c" + ], "include": [ "./include" ], diff --git a/lib/node_modules/@stdlib/number/float16/ctor/package.json b/lib/node_modules/@stdlib/number/float16/ctor/package.json index 3532f8a6ae62..b278a48473c4 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/package.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/package.json @@ -19,6 +19,7 @@ "example": "./examples", "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c new file mode 100644 index 000000000000..99cdfcdc2cb1 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/number/float16/ctor.h" +#include +#include + +/** +* Converts a half-precision floating-point number to its binary representation. +* +* @param x half-precision floating-point number +* @return 16-bit integer corresponding to a binary representation +*/ +uint16_t stdlib_float16_to_bits( stdlib_float16_t x ) { + uint16_t bits; + memcpy( &bits, &x, sizeof( bits ) ); + return bits; +} + +/** +* Converts a 16-bit binary representation to a half-precision floating-point number. +* +* @param bits 16-bit integer corresponding to a binary representation +* @return half-precision floating-point number +*/ +stdlib_float16_t stdlib_float16_from_bits( uint16_t bits ) { + stdlib_float16_t x; + memcpy( &x, &bits, sizeof( bits ) ); + return x; +} diff --git a/lib/node_modules/@stdlib/number/float16/ctor/test/test.js b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js index 1d201a8ae830..e35c0284b53f 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/test/test.js +++ b/lib/node_modules/@stdlib/number/float16/ctor/test/test.js @@ -22,7 +22,8 @@ var tape = require( 'tape' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); // eslint-disable-line id-length +var ToPrimitiveSymbol = require( '@stdlib/symbol/to-primitive' ); var Float16 = require( './../lib' ); @@ -40,7 +41,7 @@ tape( 'the function is a constructor', function test( t ) { t.end(); }); -tape( 'the constructor throws an error if provided a value property which is not a number', function test( t ) { +tape( 'the constructor throws an error if not provided a number', function test( t ) { var values; var i; @@ -76,6 +77,17 @@ tape( 'the constructor requires the `new` keyword', function test( t ) { } }); +tape( 'the constructor has a read-only `name` property', function test( t ) { + t.strictEqual( hasOwnProp( Float16, 'name' ), true, 'has property' ); + t.strictEqual( Float16.name, 'Float16', 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Float16.name = 'Foo'; + } +}); + tape( 'the constructor has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { t.strictEqual( hasOwnProp( Float16, 'BYTES_PER_ELEMENT' ), true, 'has property' ); t.strictEqual( Float16.BYTES_PER_ELEMENT, 2, 'returns expected value' ); @@ -98,7 +110,7 @@ tape( 'the constructor prototype has a read-only `BYTES_PER_ELEMENT` property', } }); -tape( 'the constructor returns an instance having a property for getting the value', function test( t ) { +tape( 'the constructor returns an instance having a property for accessing the underlying value', function test( t ) { var x = new Float16( 5.0 ); t.strictEqual( x.value, 5.0, 'returns expected value' ); t.end(); @@ -114,11 +126,9 @@ tape( 'the constructor returns an instance which throws an error when attempting } }); -tape( 'the constructor returns an instance which stores value property as half-precision floating-point numbers', function test( t ) { +tape( 'the constructor returns an instance which stores a provided value as a half-precision floating-point number', function test( t ) { var x = new Float16( 3.14 ); - - t.strictEqual( x.value, 3.140625, 'stores as half-precision' ); - + t.strictEqual( x.value, 3.140625, 'returns expected value' ); t.end(); }); @@ -144,7 +154,7 @@ tape( 'the constructor returns an instance which supports serializing an instanc 'value': 5.0 }; t.deepEqual( x.toJSON(), expected, 'returns expected value' ); - t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'returns expected value' ); x = new Float16( -5.0 ); expected = { @@ -152,34 +162,47 @@ tape( 'the constructor returns an instance which supports serializing an instanc 'value': -5.0 }; t.deepEqual( x.toJSON(), expected, 'returns expected value' ); - t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'returns expected value' ); t.end(); }); -tape( 'the constructor returns an instance which supports getting the primitive value', function test( t ) { +tape( 'the constructor returns an instance which supports converting an instance to a primitive value', function test( t ) { var x; x = new Float16( 5.0 ); - t.strictEqual( typeof x.valueOf, 'function', 'has valueOf method' ); t.strictEqual( x.valueOf(), 5.0, 'returns expected value' ); x = new Float16( -5.0 ); t.strictEqual( x.valueOf(), -5.0, 'returns expected value' ); x = new Float16( 3.14 ); - t.strictEqual( x.valueOf(), 3.140625, 'returns half-precision value' ); + t.strictEqual( x.valueOf(), 3.140625, 'returns expected value' ); x = new Float16( 0.0 ); - t.strictEqual( x.valueOf(), 0.0, 'returns zero' ); + t.strictEqual( x.valueOf(), 0.0, 'returns expected value' ); t.end(); }); -tape( 'the constructor returns an instance which supports type coercion via Symbol.toPrimitive (if supported)', function test( t ) { +tape( 'the constructor returns an instance which supports implicit type coercion', function test( t ) { var x; var y; + x = new Float16( 10.0 ); + t.strictEqual( x + 5, 15.0, 'returns expected value' ); + t.strictEqual( x * 2, 20.0, 'returns expected value' ); + + x = new Float16( 3.0 ); + y = new Float16( 2.0 ); + t.strictEqual( x + y, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.toPrimitive`, the constructor returns an instance which supports type coercion', function test( t ) { + var x; + if ( !hasToPrimitiveSymbolSupport() ) { t.ok( true, 'environment does not support Symbol.toPrimitive' ); t.end(); @@ -187,22 +210,12 @@ tape( 'the constructor returns an instance which supports type coercion via Symb } x = new Float16( 5.0 ); - t.strictEqual( typeof x[ Symbol.toPrimitive ], 'function', 'has Symbol.toPrimitive method' ); - t.strictEqual( x[ Symbol.toPrimitive ]( 'number' ), 5.0, 'returns expected value for number hint' ); - t.strictEqual( x[ Symbol.toPrimitive ]( 'default' ), 5.0, 'returns expected value for default hint' ); - t.strictEqual( x[ Symbol.toPrimitive ]( 'string' ), 5.0, 'returns expected value for string hint' ); + t.strictEqual( x[ ToPrimitiveSymbol ]( 'number' ), 5.0, 'returns expected value' ); + t.strictEqual( x[ ToPrimitiveSymbol ]( 'default' ), 5.0, 'returns expected value' ); + t.strictEqual( x[ ToPrimitiveSymbol ]( 'string' ), 5.0, 'returns expected value' ); x = new Float16( -3.14 ); - t.strictEqual( x[ Symbol.toPrimitive ](), -3.140625, 'returns half-precision value' ); - - // Test implicit type coercion: - x = new Float16( 10.0 ); - t.strictEqual( x + 5, 15.0, 'supports addition via type coercion' ); - t.strictEqual( x * 2, 20.0, 'supports multiplication via type coercion' ); - - x = new Float16( 3.0 ); - y = new Float16( 2.0 ); - t.strictEqual( x + y, 5.0, 'supports addition between two Float16 instances' ); + t.strictEqual( x[ ToPrimitiveSymbol ](), -3.140625, 'returns expected value' ); t.end(); }); From 83094bc8ae612d944fc49701c79613e485ac6924 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 18 Dec 2025 23:44:47 -0800 Subject: [PATCH 8/9] chore: fix copyright years --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: 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 --- --- .../@stdlib/number/float16/ctor/examples/c/Makefile | 2 +- .../@stdlib/number/float16/ctor/examples/c/example.c | 2 +- lib/node_modules/@stdlib/number/float16/ctor/src/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile index 70c91f4e1313..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2021 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c index b3749106a469..49fb399cf6f4 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c +++ b/lib/node_modules/@stdlib/number/float16/ctor/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2021 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c index 99cdfcdc2cb1..c2d4062c33e3 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/src/main.c +++ b/lib/node_modules/@stdlib/number/float16/ctor/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 73b4609fb419a13c84d4d195817360c01b533ec1 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 18 Dec 2025 23:57:13 -0800 Subject: [PATCH 9/9] chore: add missing folder --- 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: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 --- --- lib/node_modules/@stdlib/number/float16/ctor/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/number/float16/ctor/package.json b/lib/node_modules/@stdlib/number/float16/ctor/package.json index b278a48473c4..19c43238d2fb 100644 --- a/lib/node_modules/@stdlib/number/float16/ctor/package.json +++ b/lib/node_modules/@stdlib/number/float16/ctor/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "include": "./include",