Skip to content

Conversation

@ayush00git
Copy link
Contributor

@ayush00git ayush00git commented Jan 27, 2026

Referenced Issue - #3206

I've gone through the references in the #3206 issue and here are my implementation plans for the float16 type in go.

Implementation Plan

  1. Keep all the work in a separate folder under go/fory/float16
  2. 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.
  3. 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).
  4. 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.
  5. 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.
  6. 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:

  1. Added the Float32FromFloat16() and Float32() which properly handles the exception types, IsNaN, IsInf, overflow, underflow of exponential and mantissa.
  2. Add other basic functions and comparison methofds to the float16.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant