Skip to content

feat(javascript): add float16 support#3253

Open
ayush00git wants to merge 7 commits intoapache:mainfrom
ayush00git:feat/js-float16
Open

feat(javascript): add float16 support#3253
ayush00git wants to merge 7 commits intoapache:mainfrom
ayush00git:feat/js-float16

Conversation

@ayush00git
Copy link
Contributor

@ayush00git ayush00git commented Feb 3, 2026

Why?

Javascript package had the float16 support but during serialization it fallbacks to float32, much like the float16 was just a pseudo type which in real was a float32.

What does this PR do?

1. Adds float16(v: number | string) method to the BinaryWriterBuilder class

  float16(v: number | string) {
    return `${this.holder}.float16(${v})`
  }

2. Updated the float16 accessor in the Codegen Regsitery

CodegenRegistry.register(TypeId.FLOAT16,
  buildNumberSerializer(
    (builder, accessor) => builder.writer.float16(accessor),
    builder => builder.reader.float16()
  )
);

3. Updated the writer/number.ts and added float16 test suites in test/number.test.ts

Related Issue

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

N/A

@ayush00git
Copy link
Contributor Author

Hey @chaokunyang @theweipeng
Please, take a look at the changes and suggest me what more changes are needed.

@chaokunyang
Copy link
Collaborator

Hi@ayush00git, thansk for opening up this PR. I think we need real float16 isntead of fallbakcing to float32

@ayush00git
Copy link
Contributor Author

Hi@ayush00git, thansk for opening up this PR. I think we need real float16 isntead of fallbakcing to float32

Hey @chaokunyang
I this is the exact thing that i just fixed, previously it was falling back to float32, now its using the float16 accessor.
Or if is it something i am confused about, could you give me a exact reference of changes you want ?

@ayush00git
Copy link
Contributor Author

Hey @chaokunyang @theweipeng
could you guide me on what exactly you need on this.

@chaokunyang
Copy link
Collaborator

@ayush00git could you add float16 array support in this pr?

@ayush00git
Copy link
Contributor Author

@ayush00git could you add float16 array support in this pr?

Yaa sure, i'll add the arrays support

@ayush00git
Copy link
Contributor Author

Hey @chaokunyang
The support for float16 array was already implemented in the PR #3197 by @theweipeng
here's the file - https://github.com/apache/fory/blame/main/javascript/packages/fory/lib/gen/typedArray.ts

CodegenRegistry.register(TypeId.FLOAT16_ARRAY, build(Type.float16()));

Still I've added separate tests for float16 array support, just as a proof of this.

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.

[JavaScript] add float16 to javascript

2 participants