-
Notifications
You must be signed in to change notification settings - Fork 362
feat(go): add float16 support to go #3235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hey @chaokunyang |
Hey @chaokunyang |
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.