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

Reference for stage-3 float16array #33652

Merged
merged 3 commits into from
Jun 3, 2024
Merged

Conversation

Josh-Cena
Copy link
Member

@Josh-Cena Josh-Cena commented May 17, 2024

Part of #33561.

cc @hamishwillee maybe you want to review this.

cc @zloirock I cannot find a polyfill link for Float16Array itself and I assume that's intentional.

For whoever is reviewing this: please watch out for any copy/paste remnants since they are mostly copy/pasted...

@Josh-Cena Josh-Cena requested a review from a team as a code owner May 17, 2024 07:16
@Josh-Cena Josh-Cena requested review from teoli2003 and removed request for a team May 17, 2024 07:16
@github-actions github-actions bot added Content:JS JavaScript docs size/m 51-500 LoC changed labels May 17, 2024
Copy link
Contributor

github-actions bot commented May 17, 2024

Preview URLs (16 pages)
Flaws (5)

Note! 11 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16
Title: DataView.prototype.getFloat16()
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: javascript.builtins.DataView.getFloat16

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16
Title: DataView.prototype.setFloat16()
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: javascript.builtins.DataView.setFloat16

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array
Title: Float16Array
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: javascript.builtins.Float16Array

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array/Float16Array
Title: Float16Array() constructor
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: javascript.builtins.Float16Array.Float16Array

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/f16round
Title: Math.f16round()
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: javascript.builtins.Math.f16round
External URLs (10)

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16
Title: DataView.prototype.getFloat16()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16
Title: DataView.prototype.setFloat16()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array
Title: Float16Array


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
Title: TypedArray


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
Title: Math


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
Title: Math.fround()


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/f16round
Title: Math.f16round()

(comment last updated: 2024-05-21 00:21:56)

@zloirock
Copy link
Contributor

I cannot find a polyfill link for Float16Array itself and I assume that's intentional.

Yes, because of some specific issues I delayed adding Float16Array till reworking the architecture and dropping support of some old engines or accepting stage 4 for this proposal. The rest methods from this proposal were added to core-js.


The **`getFloat16()`** method of {{jsxref("DataView")}} instances reads 2 bytes starting at the specified byte offset of this `DataView` and interprets them as a 16-bit floating point number. There is no alignment constraint; multi-byte values may be fetched from any offset within bounds.

{{EmbedInteractiveExample("pages/js/dataview-getfloat16.html")}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't rendering - I presume is "in progress"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah...

Copy link
Collaborator

Choose a reason for hiding this comment

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

PR number please

Copy link
Member Author

Choose a reason for hiding this comment

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

const buffer = new ArrayBuffer(10);
const dataview = new DataView(buffer);
dataview.setFloat16(0, 3);
dataview.getFloat16(1); // 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it be more useful to show setting and getting the same buffer index?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that somewhat feels trivial to me though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So the question is, what does someone learn from having the getter in an example in the setter?

From this they could learn "by default the buffer is zero filled", which is interesting but requires a little thinking. It feels odd and pointless.

In the getFloat16() example you arbitrarily-sh populate the array and then get the float. This returns a value 0.00001537799835205078 which is kind of cool because it shows that the input values aren't trivially encoded into a real number. But it is also frustrating, because you can't look at the inputs and say "hey, that's the right output".

So when I saw this, I thought - ah, cool, I can see that the value in and out do match. It would be even better if I could see the values in the buffer as bytes too, but.

Anyway, those are my reasons why I would either delete the getter or make it get a value that you set.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are not fetching the default zero-filled value here. We are setting the 0th byte and 1st byte and then reading the 1st and 2nd byte. It just happens that we read out the value 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't notice that, so what does that tell you about the example?

Obviously you don't want to change this, and its a small speck in otherwise excellent docs so I'll merge.

@hamishwillee
Copy link
Collaborator

Looks great. Just a few editorial type questions.

@@ -43,51 +43,53 @@ Unlike most global objects, `Math` is not a constructor. You cannot use it with
## Static methods

- {{jsxref("Math.abs()")}}
- : Returns the absolute value of `x`.
- : Returns the absolute value of the input.
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI @Josh-Cena I replaced x by "the input" (or similar) for all the other cases in the math parent page. Left a few log/exponential cases where the use of x, y is more useful.

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

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

Approving, but see comments - such as PR for the interactive examples.

@hamishwillee hamishwillee merged commit fb44264 into mdn:main Jun 3, 2024
8 checks passed
@hamishwillee
Copy link
Collaborator

Thanks very much for sorting this out.

@Josh-Cena Josh-Cena deleted the float16array branch June 3, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs size/m 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants