Skip to content
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

Inconsistent handling of -NaN in DataView.setFloat32 #56373

Open
dy opened this issue Dec 27, 2024 · 1 comment
Open

Inconsistent handling of -NaN in DataView.setFloat32 #56373

dy opened this issue Dec 27, 2024 · 1 comment

Comments

@dy
Copy link

dy commented Dec 27, 2024

Version

v23.3.0

Platform

Darwin Dimbook.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Nov 14 18:15:21 PST 2024; root:xnu-11215.41.3~13/RELEASE_ARM64_T6041 arm64

Subsystem

No response

What steps will reproduce the bug?

const byteView = new DataView(new ArrayBuffer(4))

  for (let i = 0; i < 1e5; i++) {
    byteView.setFloat32(0,-NaN)
    if ([
      byteView.getUint8(3),
      byteView.getUint8(2),
      byteView.getUint8(1),
      byteView.getUint8(0)
    ]+'' !== [0, 0, 192, 127]+'') console.log('failed', i)
  }

Sometimes it returns [0, 0, 192, 127], the other times [0, 0, 192, 255]

How often does it reproduce? Is there a required condition?

Seems to always

What is the expected behavior? Why is that the expected behavior?

Should return consistent result

What do you see instead?

I see it changes sporadically

Additional information

Duplicate bug in chromium: https://issues.chromium.org/u/1/issues/386172182

@dy dy changed the title Inconsistent Handling of -NaN in DataView.setFloat32 Inconsistent handling of -NaN in DataView.setFloat32 Dec 27, 2024
@ljharb
Copy link
Member

ljharb commented Dec 27, 2024

This is expected, and is the nature of the language. Although the majority of the JS language only has one observable NaN, via Typed Arrays one can view bit patterns of many of the millions of NaN values in IEEE 754.

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

No branches or pull requests

2 participants