Skip to content

feat(go): add float16 support to go#3235

Merged
chaokunyang merged 19 commits intoapache:mainfrom
ayush00git:feat/go-float16
Jan 30, 2026
Merged

feat(go): add float16 support to go#3235
chaokunyang merged 19 commits intoapache:mainfrom
ayush00git:feat/go-float16

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.
  3. Created float16_serializer.go which includes, read and write methods for float16, basically a I/O driver for float16 type.
  4. Created float16_slice_serializer.go, a serializer for []float16.Float type.
  5. Created float16_array_serializer.go a seriailzer for [N]float16.Float type.

@ayush00git
Copy link
Contributor Author

ayush00git commented Jan 29, 2026

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.

@ayush00git
Copy link
Contributor Author

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.

@chaokunyang
Copy link
Collaborator

Create separate test files is better, I will check it later. And merge it if everything goes right

@ayush00git
Copy link
Contributor Author

Create separate test files is better, I will check it later. And merge it if everything goes right

Okk, in the meantime i'll try adding float16 support to other languages as you requested in the latest issues.

Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang chaokunyang merged commit 1069909 into apache:main Jan 30, 2026
55 checks passed
@ayush00git ayush00git deleted the feat/go-float16 branch February 5, 2026 08:47
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.

2 participants