{"_id":"@stdlib/number-float16-ctor","_rev":"4679226","name":"@stdlib/number-float16-ctor","description":"16-bit half-precision floating-point number.","dist-tags":{"latest":"0.1.2"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"},{"name":"stdlib-bot","email":""}],"time":{"modified":"2026-04-11T00:29:51.000Z","created":"2026-01-30T06:11:31.000Z","0.1.2":"2026-02-07T23:32:05.297Z","0.1.1":"2026-01-31T01:44:10.759Z","0.1.0":"2026-01-30T06:11:31.000Z"},"users":{},"author":{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"},"repository":{"type":"git","url":"git://github.com/stdlib-js/number-float16-ctor.git"},"versions":{"0.1.2":{"name":"@stdlib/number-float16-ctor","version":"0.1.2","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":{"doc":"./docs","include":"./include","lib":"./lib","src":"./src","dist":"./dist"},"types":"./docs/types","scripts":{},"homepage":"https://stdlib.io","repository":{"type":"git","url":"git://github.com/stdlib-js/number-float16-ctor.git"},"bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"dependencies":{"@stdlib/assert-has-to-primitive-symbol-support":"^0.1.0","@stdlib/assert-is-number":"^0.2.3","@stdlib/number-float64-base-to-float16":"^0.1.2","@stdlib/string-format":"^0.2.3","@stdlib/symbol-to-primitive":"^0.1.1","@stdlib/utils-define-nonenumerable-read-only-property":"^0.2.3","@stdlib/utils-define-read-only-property":"^0.2.3","@stdlib/error-tools-fmtprodmsg":"^0.2.3"},"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"],"funding":{"type":"opencollective","url":"https://opencollective.com/stdlib"},"_id":"@stdlib/number-float16-ctor@0.1.2","gitHead":"65ac870bcc9363ee25cdde72514d9e0783b5395e","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"shasum":"31ee0a773a34d9661ae79cb7492301718a4d52d3","size":12630,"noattachment":false,"key":"/@stdlib/number-float16-ctor/-/@stdlib/number-float16-ctor-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@stdlib/number-float16-ctor/download/@stdlib/number-float16-ctor-0.1.2.tgz"},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"},{"name":"stdlib-bot","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/number-float16-ctor_0.1.2_1770507125147_0.15553348986928195"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-02-07T23:32:05.297Z","publish_time":1770507125297,"_source_registry_name":"default","_cnpm_publish_time":1770507125297},"0.1.1":{"name":"@stdlib/number-float16-ctor","version":"0.1.1","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":{"doc":"./docs","include":"./include","lib":"./lib","src":"./src","dist":"./dist"},"types":"./docs/types","scripts":{},"homepage":"https://stdlib.io","repository":{"type":"git","url":"git://github.com/stdlib-js/number-float16-ctor.git"},"bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"dependencies":{"@stdlib/assert-has-to-primitive-symbol-support":"^0.1.0","@stdlib/assert-is-number":"^0.2.2","@stdlib/number-float64-base-to-float16":"^0.1.0","@stdlib/string-format":"^0.2.2","@stdlib/symbol-to-primitive":"^0.1.0","@stdlib/utils-define-nonenumerable-read-only-property":"^0.2.2","@stdlib/utils-define-read-only-property":"^0.2.2","@stdlib/error-tools-fmtprodmsg":"^0.2.2"},"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"],"funding":{"type":"opencollective","url":"https://opencollective.com/stdlib"},"_id":"@stdlib/number-float16-ctor@0.1.1","gitHead":"d660cabc2799c7f43cda85b7a4ff65e0995a9a1e","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"shasum":"f446b6d92d578460529eefd8d3160c5494b9b7db","size":12625,"noattachment":false,"key":"/@stdlib/number-float16-ctor/-/@stdlib/number-float16-ctor-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@stdlib/number-float16-ctor/download/@stdlib/number-float16-ctor-0.1.1.tgz"},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"},{"name":"stdlib-bot","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/number-float16-ctor_0.1.1_1769823850596_0.07647608433904884"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-01-31T01:44:10.759Z","publish_time":1769823850759,"_source_registry_name":"default","_cnpm_publish_time":1769823850759},"0.1.0":{"name":"@stdlib/number-float16-ctor","version":"0.1.0","keywords":["stdlib","stdtypes","types","data","structure","constructor","ctor","floating-point","float16","16-bit","integer","float","half","half-precision","ieee754"],"author":{"url":"https://github.com/stdlib-js/stdlib/graphs/contributors","name":"The Stdlib Authors"},"license":"Apache-2.0","_id":"@stdlib/number-float16-ctor@0.1.0","maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"},{"name":"stdlib-bot","email":""}],"contributors":[{"url":"https://github.com/stdlib-js/stdlib/graphs/contributors","name":"The Stdlib Authors"}],"homepage":"https://stdlib.io","bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"os":["aix","darwin","freebsd","linux","macos","openbsd","sunos","win32","windows"],"dist":{"shasum":"63c6a25b99d1740b06fdabd209a24cdff751f12b","size":12643,"noattachment":false,"key":"/@stdlib/number-float16-ctor/-/@stdlib/number-float16-ctor-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@stdlib/number-float16-ctor/download/@stdlib/number-float16-ctor-0.1.0.tgz"},"main":"./lib","types":"./docs/types","engines":{"npm":">2.7.0","node":">=0.10.0"},"funding":{"url":"https://opencollective.com/stdlib","type":"opencollective"},"gitHead":"c300ff914062f53a0fcf2d195f694bbb90cc96a2","scripts":{},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"repository":{"url":"git://github.com/stdlib-js/number-float16-ctor.git","type":"git"},"_npmVersion":"10.8.2","description":"16-bit half-precision floating-point number.","directories":{"doc":"./docs","lib":"./lib","src":"./src","dist":"./dist","include":"./include"},"_nodeVersion":"20.20.0","dependencies":{"@stdlib/string-format":"^0.2.2","@stdlib/assert-is-number":"^0.2.2","@stdlib/symbol-to-primitive":"github:stdlib-js/symbol-to-primitive#main","@stdlib/error-tools-fmtprodmsg":"^0.2.2","@stdlib/number-float64-base-to-float16":"^0.1.0","@stdlib/utils-define-read-only-property":"^0.2.2","@stdlib/assert-has-to-primitive-symbol-support":"github:stdlib-js/assert-has-to-primitive-symbol-support#main","@stdlib/utils-define-nonenumerable-read-only-property":"^0.2.2"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/number-float16-ctor_0.1.0_1769753490842_0.4422356344130034","host":"s3://npm-registry-packages-npm-production"},"_cnpmcore_publish_time":"2026-01-30T06:11:31.000Z","publish_time":1769753491000,"_source_registry_name":"default","_cnpm_publish_time":1769753491000}},"readme":"<!--\n\n@license Apache-2.0\n\nCopyright (c) 2025 The Stdlib Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n-->\n\n\n<details>\n  <summary>\n    About stdlib...\n  </summary>\n  <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>\n  <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>\n  <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>\n  <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href=\"https://github.com/stdlib-js/stdlib\">GitHub</a>, and please consider <a href=\"https://opencollective.com/stdlib\">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>\n</details>\n\n# Float16\n\n[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->\n\n> 16-bit half-precision floating-point number.\n\n<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->\n\n<section class=\"intro\">\n\n</section>\n\n<!-- /.intro -->\n\n<!-- Package usage documentation. -->\n\n<section class=\"installation\">\n\n## Installation\n\n```bash\nnpm install @stdlib/number-float16-ctor\n```\n\n</section>\n\n<section class=\"usage\">\n\n## Usage\n\n```javascript\nvar Float16 = require( '@stdlib/number-float16-ctor' );\n```\n\n#### Float16( value )\n\n16-bit half-precision floating-point number constructor.\n\n```javascript\nvar x = new Float16( 5.0 );\n// returns <Float16>\n```\n\n* * *\n\n## Properties\n\n#### Float16.name\n\nStatic property returning the constructor name.\n\n```javascript\nvar str = Float16.name;\n// returns 'Float16'\n```\n\n#### Float16.BYTES_PER_ELEMENT\n\nSize (in bytes) of the underlying value.\n\n```javascript\nvar nbytes = Float16.BYTES_PER_ELEMENT;\n// returns 2\n```\n\n#### Float16.prototype.BYTES_PER_ELEMENT\n\nSize (in bytes) of the underlying value.\n\n```javascript\nvar x = new Float16( 5.0 );\n\nvar nbytes = x.BYTES_PER_ELEMENT;\n// returns 2\n```\n\n### Instance\n\nA `Float16` instance has the following properties...\n\n#### value\n\nA **read-only** property returning the underlying value as a number.\n\n```javascript\nvar x = new Float16( 5.0 );\n\nvar v = x.value;\n// returns 5.0\n```\n\n* * *\n\n## Methods\n\n### Accessor Methods\n\nThese methods do **not** mutate a `Float16` instance and, instead return a half-precision floating-point number representation.\n\n#### Float16.prototype.toString()\n\nReturns a string representation of a `Float16` instance.\n\n```javascript\nvar x = new Float16( 5.0 );\nvar str = x.toString();\n// returns '5'\n\nx = new Float16( -3.14 );\nstr = x.toString();\n// returns '-3.140625'\n```\n\n#### Float16.prototype.toJSON()\n\nReturns a [JSON][json] representation of a `Float16` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Float16` instance.\n\n```javascript\nvar x = new Float16( 5.0 );\n\nvar o = x.toJSON();\n/*\n  {\n    \"type\": \"Float16\",\n    \"value\": 5.0\n  }\n*/\n```\n\nTo [revive][mdn-json-parse] a `Float16` number from a [JSON][json] `string`, see [@stdlib/number/float16/reviver][@stdlib/number/float16/reviver].\n\n#### Float16.prototype.valueOf()\n\nConverts a `Float16` instance to a primitive value.\n\n```javascript\nvar x = new Float16( 5.0 );\nvar v = x.valueOf();\n// returns 5.0\n\nx = new Float16( 3.14 );\nv = x.valueOf();\n// returns 3.140625\n```\n\n</section>\n\n<!-- /.usage -->\n\n* * *\n\n<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"notes\">\n\n## Notes\n\n-   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.\n-   A half-precision floating-point number has a range of approximately `±6.55e4` and a precision of about 3-4 decimal digits.\n\n</section>\n\n<!-- /.notes -->\n\n* * *\n\n<!-- Package usage examples. -->\n\n<section class=\"examples\">\n\n## Examples\n\n<!-- eslint no-undef: \"error\" -->\n\n```javascript\nvar Float16 = require( '@stdlib/number-float16-ctor' );\n\nvar x = new Float16( 3.14 );\n\nconsole.log( 'type: %s', typeof x );\n// => 'type: object'\n\nconsole.log( 'str: %s', x );\n// => 'str: 3.140625'\n\nconsole.log( 'value: %d', x.value );\n// => 'value: 3.140625'\n\nconsole.log( 'JSON: %s', JSON.stringify( x ) );\n// => 'JSON: {\"type\":\"Float16\",\"value\":3.140625}'\n```\n\n</section>\n\n<!-- /.examples -->\n\n<!-- C interface documentation. -->\n\n* * *\n\n<section class=\"c\">\n\n## C APIs\n\n<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->\n\n<section class=\"intro\">\n\n</section>\n\n<!-- /.intro -->\n\n<!-- C usage documentation. -->\n\n<section class=\"usage\">\n\n### Usage\n\n```c\n#include \"stdlib/number/float16/ctor.h\"\n```\n\n#### stdlib_float16_t\n\nAn opaque type definition for a half-precision floating-point number.\n\n```c\nstdlib_float16_t v = stdlib_float16_from_bits( 51648 );\n```\n\n#### stdlib_float16_bits_t\n\nAn opaque type definition for a union for accessing the underlying binary representation of a half-precision floating-point number.\n\n```c\n#include <stdint.h>\n\nstdlib_float16_t x = stdlib_float16_from_bits( 51648 );\n\nstdlib_float16_bits_t y;\ny.value = x;\n\nuint16_t bits = y.bits;\n// returns 51648\n```\n\nThe union has the following members:\n\n-   **value**: `stdlib_float16_t` half-precision floating-point number.\n-   **bits**: `uint16_t` binary representation.\n\nThe 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.\n\n#### stdlib_float16_from_bits( bits )\n\nConverts a 16-bit binary representation to a half-precision floating-point number.\n\n```c\nstdlib_float16_t v = stdlib_float16_from_bits( 51648 ); // => -11.5\n```\n\nThe function accepts the following arguments:\n\n-   **bits**: `[in] uint16_t` 16-bit integer corresponding to a binary representation.\n\n#### stdlib_float16_to_bits( x )\n\nConverts a half-precision floating-point number to a 16-bit binary representation.\n\n```c\n#include <stdint.h>\n\nstdlib_float16_t v = stdlib_float16_from_bits( 51648 ); // => -11.5\n\nuint16_t bits = stdlib_float16_to_bits( v );\n```\n\nThe function accepts the following arguments:\n\n-   **x**: `[in] stdlib_float16_t` half-precision floating-point number.\n\n</section>\n\n<!-- /.usage -->\n\n<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"notes\">\n\n### Notes\n\n-   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.\n\n</section>\n\n<!-- /.notes -->\n\n<!-- C API usage examples. -->\n\n<section class=\"examples\">\n\n### Examples\n\n```c\n#include \"stdlib/number/float16/ctor.h\"\n#include <stdint.h>\n#include <stdio.h>\n\nint main( void ) {\n  const stdlib_float16_t x[] = {\n    stdlib_float16_from_bits( 51648 ), // -11.5\n    stdlib_float16_from_bits( 18880 )  // 11.5\n  };\n\n  int i;\n  for ( i = 0; i < 2; i++ ) {\n    printf( \"%d\\n\", stdlib_float16_to_bits( x[ i ] ) );\n  }\n}\n```\n\n</section>\n\n<!-- /.examples -->\n\n</section>\n\n<!-- /.c -->\n\n<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"references\">\n\n</section>\n\n<!-- /.references -->\n\n<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->\n\n<section class=\"related\">\n\n</section>\n\n<!-- /.related -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n\n<section class=\"main-repo\" >\n\n* * *\n\n## Notice\n\nThis package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.\n\nFor more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].\n\n#### Community\n\n[![Chat][chat-image]][chat-url]\n\n---\n\n## License\n\nSee [LICENSE][stdlib-license].\n\n\n## Copyright\n\nCopyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].\n\n</section>\n\n<!-- /.stdlib -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"links\">\n\n[npm-image]: http://img.shields.io/npm/v/@stdlib/number-float16-ctor.svg\n[npm-url]: https://npmjs.org/package/@stdlib/number-float16-ctor\n\n[test-image]: https://github.com/stdlib-js/number-float16-ctor/actions/workflows/test.yml/badge.svg?branch=v0.1.2\n[test-url]: https://github.com/stdlib-js/number-float16-ctor/actions/workflows/test.yml?query=branch:v0.1.2\n\n[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/number-float16-ctor/main.svg\n[coverage-url]: https://codecov.io/github/stdlib-js/number-float16-ctor?branch=main\n\n<!--\n\n[dependencies-image]: https://img.shields.io/david/stdlib-js/number-float16-ctor.svg\n[dependencies-url]: https://david-dm.org/stdlib-js/number-float16-ctor/main\n\n-->\n\n[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg\n[chat-url]: https://stdlib.zulipchat.com\n\n[stdlib]: https://github.com/stdlib-js/stdlib\n\n[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors\n\n[umd]: https://github.com/umdjs/umd\n[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\n\n[deno-url]: https://github.com/stdlib-js/number-float16-ctor/tree/deno\n[deno-readme]: https://github.com/stdlib-js/number-float16-ctor/blob/deno/README.md\n[umd-url]: https://github.com/stdlib-js/number-float16-ctor/tree/umd\n[umd-readme]: https://github.com/stdlib-js/number-float16-ctor/blob/umd/README.md\n[esm-url]: https://github.com/stdlib-js/number-float16-ctor/tree/esm\n[esm-readme]: https://github.com/stdlib-js/number-float16-ctor/blob/esm/README.md\n[branches-url]: https://github.com/stdlib-js/number-float16-ctor/blob/main/branches.md\n\n[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/number-float16-ctor/main/LICENSE\n\n[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985\n\n[json]: http://www.json.org/\n\n[mdn-json-stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify\n\n[mdn-json-parse]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse\n\n[@stdlib/number/float16/reviver]: https://www.npmjs.com/package/@stdlib/number-float16-reviver\n\n<!-- <related-links> -->\n\n<!-- </related-links> -->\n\n</section>\n\n<!-- /.links -->\n","_attachments":{},"homepage":"https://stdlib.io","bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"license":"Apache-2.0"}