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
Single precision floating point issues #4251
Comments
This might be since emscripten uses doubles by default for floats? See this faq entry. Would be nice if we could stop doing that, but optimized floats are still slow on at least chrome. |
If I may off topic a little @kripken: Will WebAssembly solve problem with float precision and integer 64bit emulation? |
Yes, f32 and i64 are basic types that will be present in all browsers with wasm support, so they should both be at full speed pretty much everywhere. |
(I'm working on the same project as @sagamusix, thus I know the context of the original bug report)
I'm still kind of confused about what kind of rounding error here would result in a 1.5% error. The code in question does not rely on any kind of reduced precision from using float instead of double. Promoting all floats to doubles thus should only increase precision and not reduce it. Further investigation shows: The problematic operation here is std::pow. Trying both the float and double versions explicitly shows the float version misbehaving:
Output:
That's an almost 1.5% error from a standard library function when called with floats instead of doubles. |
I believe we use |
I reduced the test case even further:
|
Results on Firefox44/32bit/Windows, Firefox45.0/x86-64/Ubuntu14.04 and nodejs-4.1.1/x86-64/Ubuntu14.04 are all the same for me. To me, this does not look like a browser problem. |
I can confirm it's not a browser problem. Also that And looks like with As to why the problem is so large, |
Getting the whole calculation before
|
I was having the same problem. I investigated a bit more into @manxorist 's test case. I have attached the |
Probably in What goes wrong in those compiled methods is that they are sensitive to float precision, I believe. Perhaps they could be rewritten, but it wouldn't be easy ;) Overall, the solution is just to use |
The problem with |
That 3x slowdown is in chrome, I guess? Yeah, they are the reason we can't turn this on by default. (If it's another browser, that might be an unknown issue that needs to be filed for that browser.) |
Yes, this is in both Node.js and Chome 50. |
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@10619 56274372-70c3-4bfc-bfc3-4c3a0b034d27
[Ref] Test: Add test for <emscripten-core/emscripten#4251>. ........ git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.27@10620 56274372-70c3-4bfc-bfc3-4c3a0b034d27
git-svn-id: https://source.openmpt.org/svn/openmpt@10619 56274372-70c3-4bfc-bfc3-4c3a0b034d27
[Ref] Test: Add test for <emscripten-core/emscripten#4251>. ........ git-svn-id: https://source.openmpt.org/svn/openmpt@10620 56274372-70c3-4bfc-bfc3-4c3a0b034d27
I can reproduce this problem with emscripten 1.36.0 on node.js 4.1.1. I have not checked any other versions in-between. |
[Ref] Test: Add test for <emscripten-core/emscripten#4251>. ........ git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.27@10620 56274372-70c3-4bfc-bfc3-4c3a0b034d27
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
The calculations done by the following program show huge discrepancies compared to compiling them natively in GCC, Clang or MSVC:
Output:
That's an error of about 1.5%, which is quite high.
Changing the calculations to use double precision leads to a more acceptable result:
The text was updated successfully, but these errors were encountered: