Skip to content

Float32List.join() produces unpredictable results #43267

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

Closed
sgrekhov opened this issue Aug 31, 2020 · 3 comments
Closed

Float32List.join() produces unpredictable results #43267

sgrekhov opened this issue Aug 31, 2020 · 3 comments
Labels
closed-as-intended Closed as the reported issue is expected behavior

Comments

@sgrekhov
Copy link
Contributor

  var l1 = new Float32List.fromList([1.11, 2.11]);
  var s1 = l1.join(',');
  print(s1); // prints 1.1100000143051147,2.109999895095825

  var l2 = new Float32List.fromList([1.25, 2.25]);
  var s2 = l2.join(',');
  print(s2); // prints 1.25,2.25

Why results are so different? Why 1.25 is printed as 1.25 but 1.11 as 1.1100000143051147?

Dart SDK version: 2.10.0-59.0.dev (dev) (Tue Aug 25 18:05:44 2020 -0700) on "windows_x64"

@whesse
Copy link
Contributor

whesse commented Aug 31, 2020

Floating point numbers can only represent fractional powers of 2 like 1/2, 1/4, 3/8, 999/1024 exactly.
1.11 as a floating point number is not exactly 1.11.
Please rewrite these tests with only numbers like 12.625 or 0.03125, or include an inaccuracy factor of about 1/100000, or whatever is needed.

@whesse
Copy link
Contributor

whesse commented Aug 31, 2020

Also the Float32x4 reciprocal square root and reciprocal tests are failing.
The error given by the hardware reciprocal square root approximation is only within 1/1000 of the correct answer, not 1/10000.
The intel doc says:
Compute the approximate reciprocal square root of the lower single-precision (32-bit) floating-point element in a, store the result in the lower element of dst, and copy the upper 3 packed elements from a to the upper elements of dst. The maximum relative error for this approximation is less than 1.5*2^-12.

Reciprocal approximation is within https://www.felixcloutier.com/x86/rcpss the same limit.

Does the spec say anything about the approximation accuracy? These two operations are specifically designed to be fast and approximate.

@mraleph mraleph added the closed-as-intended Closed as the reported issue is expected behavior label Aug 31, 2020
@mraleph mraleph closed this as completed Aug 31, 2020
@sgrekhov
Copy link
Contributor Author

sgrekhov commented Sep 1, 2020

dart-lang/co19@4f7d3e7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

3 participants