Skip to content

Add support for Float16Array#6005

Open
hoodmane wants to merge 7 commits intopyodide:mainfrom
hoodmane:float16array
Open

Add support for Float16Array#6005
hoodmane wants to merge 7 commits intopyodide:mainfrom
hoodmane:float16array

Conversation

@hoodmane
Copy link
Member

  • Add a CHANGELOG entry
  • Add / update tests
  • Add new / update outdated documentation

arrayType = BigUint64Array;
break;
case "e":
arrayType = Float16Array;
Copy link
Member

@ryanking13 ryanking13 Nov 27, 2025

Choose a reason for hiding this comment

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

Float16Array is not be available in old browsers and Node < 24. Maybe we need to handle those cases?

Copy link
Member

Choose a reason for hiding this comment

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

Would we consider Node 24 too early? Also, not sure if this question is silly, but would we need to polyfill Float16Array (or use an existing one like https://github.com/petamoriken/float16)?

Also, I think we would need to use the --js-float16array flag.

Copy link
Member Author

@hoodmane hoodmane Nov 28, 2025

Choose a reason for hiding this comment

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

No polyfill, it just will fail with an error on old runtimes just like it used to do.

On node 24, it is available by default with no flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

It fails with:

JsException: ReferenceError: Float16Array is not defined

when this is used, which I think is okay. If you want though I could change it to an error saying the JS runtime is too old to support Float16.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, glad to hear it's supported in Node 24 without any flags (I don't know why, but it is hard to find their release notes and CHANGELOG indicating this)

Yes, I think a clearer error message to the user would be useful, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

If it fails in the runtime not in compile time, that's fine with me. People who use Float16Array should be aware of whether their environment supports Float16Array.

We will need to make tsd happy to make our CI pass though.

  ../../dist/ffi.d.ts:6:124
  ✖    6:124  Cannot find name Float16Array. Did you mean Float64Array?                                                          
  ✖   20:1    A computed property name in a class property declaration must have a simple literal type or a unique symbol type.  

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.

3 participants