You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've gone through the references in the #3206 issue and here are my implementation plans for the float16 type in go.
Implementation Plan
Keep all the work in a separate folder under go/fory/float16
Core Type Definition (float16.go): Create a new Float16 type based on uint16 to hold the raw bits, implementing essential constants (NaN, Inf) and conversion methods (FromFloat32(), Float32()) that handle IEEE 754 logic.
Math & Utility Methods: Implement arithmetic operations (Add, Sub, Mul, Div) by temporarily promoting values to float32 for calculation, along with classification helpers like IsNaN, IsFinite, and strict IEEE 754 comparison methods (Equal, Less).
Serialization Logic (float16_serializer.go): Develop a dedicated float16Serializer that handles writing the 2-byte structure to the wire with the correct FLOAT16 tag and reading it back.
System Integration (types.go, primitive.go): Update the Fory type system to recognize float16 by adding new Dispatch IDs (PrimitiveFloat16DispatchId), registering the serializer, and setting the fixed size to 2 bytes.
I/O & Array Support (writer.go, reader.go, array_primitive.go): Modify the main read/write loops to process the new Dispatch IDs and add support for efficient []float16 arrays using the FLOAT16_ARRAY wire type.
What's implemented so far:
Added the Float32FromFloat16() and Float32() which properly handles the exception types, IsNaN, IsInf, overflow, underflow of exponential and mantissa.
Add other basic functions and comparison methofds to the float16.go.
Created float16_serializer.go which includes, read and write methods for float16, basically a I/O driver for float16 type.
Created float16_slice_serializer.go, a serializer for []float16.Float type.
Created float16_array_serializer.go a seriailzer for [N]float16.Float type.
Hey @chaokunyang
I just got a little confused, i have created separate files for tests as well like - float16_serialization_test.go, float16_test.go and slice_primitive_test.go are these also to do appended in some existing tests files? Like for the arrays tests there was a existing file array_primitive_test.go so I appended that tests to that file.
Hey @chaokunyang
I'm done with the implementations, and for now i've created two separate files - primitive.go and primitive_test.go to include the unit tests for float16 just to prefer isolation of this type, as go doesn't supports it natively.
If you prefer merging them to the existing fory_typed_test.go and buffer_test.go, i'll do that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.float16_serializer.gowhich includes, read and write methods forfloat16, basically a I/O driver for float16 type.float16_slice_serializer.go, a serializer for[]float16.Floattype.float16_array_serializer.goa seriailzer for[N]float16.Floattype.