feat(go): add float16 support to go #3235
Open
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.
Referenced Issue - #3206
I've gone through the references in the #3206 issue and here are my implementation plans for the
float16type in go.Implementation Plan
go/fory/float16float16.go): Create a newFloat16type based onuint16to hold the raw bits, implementing essential constants (NaN,Inf) and conversion methods (FromFloat32(),Float32()) that handle IEEE 754 logic.Add,Sub,Mul,Div) by temporarily promoting values tofloat32for calculation, along with classification helpers likeIsNaN,IsFinite, and strict IEEE 754 comparison methods (Equal,Less).float16_serializer.go): Develop a dedicatedfloat16Serializerthat handles writing the 2-byte structure to the wire with the correctFLOAT16tag and reading it back.types.go,primitive.go): Update the Fory type system to recognizefloat16by adding new Dispatch IDs (PrimitiveFloat16DispatchId), registering the serializer, and setting the fixed size to 2 bytes.writer.go,reader.go,array_primitive.go): Modify the main read/write loops to process the new Dispatch IDs and add support for efficient[]float16arrays using theFLOAT16_ARRAYwire type.What's implemented so far:
Float32FromFloat16()andFloat32()which properly handles the exception types, IsNaN, IsInf, overflow, underflow of exponential and mantissa.float16.go.