Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

toString() Test is more strict than spec for Float32x4. #295

Open
nmostafa opened this issue Oct 24, 2015 · 5 comments
Open

toString() Test is more strict than spec for Float32x4. #295

nmostafa opened this issue Oct 24, 2015 · 5 comments

Comments

@nmostafa
Copy link
Contributor

Currently, we verify correctness by strict string comparison, causing failures due to subtle difference in formatting or precision (e.g. "SIMD.Float32x4(1.0, 2.0, 3.0, 4.0)" !== "SIMD.Float32x4(1, 2, 3, 4)"). The spec doesn't dictate specific formatting on lane values.

Better to do CheckValue(.., v, eval(v.toString()), assuming NaNs and Infinities are not tested ?

@ljharb
Copy link
Member

ljharb commented Oct 24, 2015

What would be the purpose of providing the precision? 1.0 and 1 are equivalent in JavaScript, and both stringify as "1".

I would expect the spec to dictate standard JavaScript string representations for numbers. When would that not be desirable?

@nmostafa
Copy link
Contributor Author

I agree that using Number.prototype.ToString() is the right answer, and after a closer look at the spec, I think that's the intent:

Let elements be CreateArrayFromList(argument.[[SIMDElements]]).
Let t be the string "SIMD", e.g., "Float32x4".
Let e be ArrayJoin(elements, ", ").
Return a new String value computed by concatenating the values "SIMD.", t, "(", e, and ")".

However, [[SIMDElements]] is defined as an ECMAScript List of values, without specifying the type of those values. Should we add Number to the definition ?

[[SIMDElements]], which is a List of values representing the SIMD contents.

@littledan
Copy link
Member

Remember that they may be Booleans. It's true that the spec is unclear; I was imagining that the semantics would be like +, which would call Number.prototype.toString() on Numbers and Boolean.prototype.toString() on Booleans. How does that sound? Spec pull requests are welcome.

@ljharb
Copy link
Member

ljharb commented Nov 13, 2015

Simply calling the abstract operation ToString on each value should do it, no?

@nmostafa
Copy link
Contributor Author

Yes. I think just adding a note under [[SIMDElements]] definition indicating that values are either Number or Booleans depending on the SIMDTypeDescriptor should be enough. I will submit a PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants