{"id":22836018,"url":"https://github.com/x448/float16","last_synced_at":"2026-01-23T00:26:50.937Z","repository":{"id":39979061,"uuid":"230667560","full_name":"x448/float16","owner":"x448","description":"float16 provides IEEE 754 half-precision format (binary16) with correct conversions to/from float32","archived":false,"fork":false,"pushed_at":"2025-12-14T15:07:56.000Z","size":221,"stargazers_count":89,"open_issues_count":3,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-15T07:32:11.697Z","etag":null,"topics":["binary16","float16","floating-point","go","golang","half-precision","ieee754"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/x448.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-28T21:09:45.000Z","updated_at":"2025-12-14T15:07:52.000Z","dependencies_parsed_at":"2025-12-13T17:17:14.815Z","dependency_job_id":null,"html_url":"https://github.com/x448/float16","commit_stats":null,"previous_names":["cbor-go/float16"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/x448/float16","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x448%2Ffloat16","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x448%2Ffloat16/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x448%2Ffloat16/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x448%2Ffloat16/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x448","download_url":"https://codeload.github.com/x448/float16/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x448%2Ffloat16/sbom","scorecard":{"id":268628,"data":{"date":"2025-07-07","repo":{"name":"github.com/x448/float16","commit":"e8df69d114b7f257f9c40e48d700b0c6a1f55604"},"scorecard":{"version":"v5.2.1-18-gbb9c347d","commit":"bb9c347dff6349d986baab6578a46d68a5524c62"},"score":8.6,"checks":[{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#code-review"}},{"name":"Maintained","score":6,"reason":"8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#maintained"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#security-policy"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":10,"reason":"all dependencies are pinned","details":["Info:  10 out of  10 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/ci.yml:31","Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:24","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:25","Info: jobLevel 'contents' permission set to 'read': .github/workflows/cover.yml:35","Info: jobLevel 'contents' permission set to 'read': .github/workflows/safer-golangci-lint.yml:61","Info: found token with 'none' permissions: .github/workflows/ci.yml:1","Info: found token with 'none' permissions: .github/workflows/codeql-analysis.yml:1","Info: found token with 'none' permissions: .github/workflows/cover.yml:1","Info: found token with 'none' permissions: .github/workflows/safer-golangci-lint.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: SAST configuration detected: CodeQL","Info: all commits (30) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T12:48:34.511Z","repository_id":39979061,"created_at":"2025-08-17T12:48:34.511Z","updated_at":"2025-08-17T12:48:34.511Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28676090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T20:48:19.482Z","status":"ssl_error","status_checked_at":"2026-01-22T20:48:14.968Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary16","float16","floating-point","go","golang","half-precision","ieee754"],"created_at":"2024-12-12T23:00:50.701Z","updated_at":"2026-01-23T00:26:50.927Z","avatar_url":"https://github.com/x448.png","language":"Go","funding_links":[],"categories":["Wireless Communication"],"sub_categories":["WASI and WASM Unknown"],"readme":"# Float16 (Binary16) in Go/Golang\n[![](https://github.com/x448/float16/workflows/ci/badge.svg)](https://github.com/x448/float16/actions?query=workflow%3Aci)\n[![](https://github.com/x448/float16/workflows/cover%20100%25/badge.svg)](https://github.com/x448/float16/actions?query=workflow%3A%22cover+100%25%22)\n[![](https://github.com/x448/float16/workflows/linters/badge.svg)](https://github.com/x448/float16/actions?query=workflow%3Alinters)\n[![Go Report Card](https://goreportcard.com/badge/github.com/x448/float16)](https://goreportcard.com/report/github.com/x448/float16)\n[![Release](https://img.shields.io/github/release/x448/float16.svg?style=flat-square)](https://github.com/x448/float16/releases)\n[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/x448/float16/master/LICENSE)\n\n[__`x448/float16`__](https://github.com/x448/float16) package provides [IEEE 754 half-precision floating-point format (binary16)](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) with IEEE 754 default rounding for conversions. IEEE 754-2008 refers to this 16-bit floating-point format as binary16.\n\nIEEE 754 default rounding (\"Round-to-Nearest RoundTiesToEven\") is considered the most accurate and statistically unbiased estimate of the true result.\n\nAll possible 4+ billion floating-point conversions with this library are verified to be correct.\n\nLowercase \"float16\" refers to IEEE 754 binary16. And capitalized \"Float16\" refers to exported Go data type.\n\nThis library started as a contribution to [fxamacker/cbor](https://github.com/fxamacker/cbor) and became a standalone library to allow use by other software.\n\nSoftware using this library include [cbor](https://github.com/fxamacker/cbor) and [ollama](https://github.com/ollama/ollama).\n\n\u003e [!NOTE]\n\u003e This float16 library is extremely well-tested:\n\u003e - 100% code coverage for both `go test` and `go test -short`.\n\u003e - All 4294967296 possible float32 to float16 conversions (in pure Go) are confirmed to be correct.\n\u003e - All 65536 possible float16 to float32 conversions (in pure Go) are confirmed to be correct.\n\n## Features\nCurrent features include:\n\n* float16 to float32 conversions use lossless conversion.\n* float32 to float16 conversions use IEEE 754-2008 \"Round-to-Nearest RoundTiesToEven\".\n* conversions using pure Go take about 2.65 ns/op on a desktop amd64.\n* unit tests provide 100% code coverage and check all possible 4+ billion conversions.\n* other functions include: IsInf(), IsNaN(), IsNormal(), PrecisionFromfloat32(), String(), etc.\n* all functions in this library use zero allocs except String().\n\n## Status\nThis library is ready for production use on supported platforms.  The version number \u003c 1.0 indicates more functions and options are planned but not yet published.\n\nCurrent status:\n\n* Core API is done and breaking API changes are unlikely.\n* 100% of unit tests pass:\n  * short mode (`go test -short`) tests around 65765 conversions in 0.005s.  \n  * normal mode (`go test`) tests all possible 4+ billion conversions in about 95s.  \n* 100% code coverage with both short mode and normal mode.  \n* Tested on amd64, arm64, ppc64le, and s390x.\n \nRoadmap:\n\n* Add functions for fast batch conversions leveraging SIMD when supported by hardware.\n* Speed up unit test when verifying all possible 4+ billion conversions.\n \n## Float16 to Float32 Conversion\nConversions from float16 to float32 are lossless conversions.  All 65536 possible float16 to float32 conversions (in pure Go) are confirmed to be correct.  \n\nUnit tests take a fraction of a second to check all 65536 expected values for float16 to float32 conversions.\n\n## Float32 to Float16 Conversion\nConversions from float32 to float16 use IEEE 754 default rounding (\"Round-to-Nearest RoundTiesToEven\").  All 4294967296 possible float32 to float16 conversions (in pure Go) are confirmed to be correct.  \n\nUnit tests in normal mode take about 1-2 minutes to check all 4+ billion float32 input values and results for Fromfloat32(), FromNaN32ps(), and PrecisionFromfloat32(). \n\nUnit tests in short mode use a small subset (around 229 float32 inputs) and finish in under 0.01 second while still reaching 100% code coverage.\n\n## Usage\nInstall with `go get github.com/x448/float16`.\n```\n// Convert float32 to float16\npi := float32(math.Pi)\npi16 := float16.Fromfloat32(pi)\n\n// Convert float16 to float32\npi32 := pi16.Float32()\n\n// PrecisionFromfloat32() is faster than the overhead of calling a function.\n// This example only converts if there's no data loss and input is not a subnormal.\nif float16.PrecisionFromfloat32(pi) == float16.PrecisionExact {\n    pi16 := float16.Fromfloat32(pi)\n}\n```\n\n## Float16 Type and API\nFloat16 (capitalized) is a Go type with uint16 as the underlying state.  There are 6 exported functions and 9 exported methods.\n```\npackage float16 // import \"github.com/x448/float16\"\n\n// Exported types and consts\ntype Float16 uint16\nconst ErrInvalidNaNValue = float16Error(\"float16: invalid NaN value, expected IEEE 754 NaN\")\n\n// Exported functions\nFromfloat32(f32 float32) Float16   // Float16 number converted from f32 using IEEE 754 default rounding\n                                      with identical results to AMD and Intel F16C hardware. NaN inputs \n                                      are converted with quiet bit always set on, to be like F16C.\n\nFromNaN32ps(nan float32) (Float16, error)   // Float16 NaN without modifying quiet bit.\n                                            // The \"ps\" suffix means \"preserve signaling\".\n                                            // Returns sNaN and ErrInvalidNaNValue if nan isn't a NaN.\n                                 \nFrombits(b16 uint16) Float16       // Float16 number corresponding to b16 (IEEE 754 binary16 rep.)\nNaN() Float16                      // Float16 of IEEE 754 binary16 not-a-number\nInf(sign int) Float16              // Float16 of IEEE 754 binary16 infinity according to sign\n\nPrecisionFromfloat32(f32 float32) Precision  // quickly indicates exact, ..., overflow, underflow\n                                             // (inline and \u003c 1 ns/op)\n// Exported methods\n(f Float16) Float32() float32      // float32 number converted from f16 using lossless conversion\n(f Float16) Bits() uint16          // the IEEE 754 binary16 representation of f\n(f Float16) IsNaN() bool           // true if f is not-a-number (NaN)\n(f Float16) IsQuietNaN() bool      // true if f is a quiet not-a-number (NaN)\n(f Float16) IsInf(sign int) bool   // true if f is infinite based on sign (-1=NegInf, 0=any, 1=PosInf)\n(f Float16) IsFinite() bool        // true if f is not infinite or NaN\n(f Float16) IsNormal() bool        // true if f is not zero, infinite, subnormal, or NaN.\n(f Float16) Signbit() bool         // true if f is negative or negative zero\n(f Float16) String() string        // string representation of f to satisfy fmt.Stringer interface\n```\nSee [API](https://godoc.org/github.com/x448/float16) at godoc.org for more info.\n\n## Benchmarks\nConversions (in pure Go) are around 2.65 ns/op for float16 -\u003e float32 and float32 -\u003e float16 on amd64. Speeds can vary depending on input value.\n\n```\nAll functions have zero allocations except float16.String().\n\nFromFloat32pi-2  2.59ns ± 0%    // speed using Fromfloat32() to convert a float32 of math.Pi to Float16\nToFloat32pi-2    2.69ns ± 0%    // speed using Float32() to convert a float16 of math.Pi to float32\nFrombits-2       0.29ns ± 5%    // speed using Frombits() to cast a uint16 to Float16\n\nPrecisionFromFloat32-2  0.29ns ± 1%  // speed using PrecisionFromfloat32() to check for overflows, etc.\n```\n\n## System Requirements\n* Go 1.12 (or newer).\n* amd64, arm64, ppc64le, or s390x.\n\nOther architectures and Go versions may work, but are not tested regularly.\n\n## Special Thanks\nSpecial thanks to Kathryn Long (starkat99) for creating [half-rs](https://github.com/starkat99/half-rs), a very nice rust implementation of float16.\n\n## License\nCopyright © 2019-present Montgomery Edwards⁴⁴⁸ and Faye Amacker.\n\nx448/float16 is licensed under the MIT License.  See [LICENSE](LICENSE) for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx448%2Ffloat16","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx448%2Ffloat16","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx448%2Ffloat16/lists"}