feat(javascript): add bfloat16 and bfloat16_array support #3328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds bfloat16 and bfloat16_array support to the Fory JavaScript runtime and codegen, following the same structure as the existing float16 implementation.
Fixes #3288
Changes
Runtime
fromBits()/toBits()andfromFloat32()/toFloat32()(IEEE 754 compliant, round-to-nearest ties-to-even for float32→bfloat16).Uint16Arrayfor packed bfloat16 arrays; supports iteration andfromRaw()for deserialization.Type system & serialization
Type.bfloat16()andType.bfloat16Array().BFloat16(no raw uint16 in public API).gen/builder.ts,gen/number.ts, andgen/typedArray.tsupdated for bfloat16 and bfloat16_array.API
BFloat16andBFloat16Arrayexported from the package.BFloat16 | numberfor scalar bfloat16; arrays acceptBFloat16[]orBFloat16Array.Tests
bfloat16Arraywith number array and withBFloat16Array.Checklist