-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix simulation consistency and memory leaks #35
base: master
Are you sure you want to change the base?
Conversation
Thanks for PR, can you have a look at linthub and see about addressing those issues? As for the rest.. it seems we lost python 2.6 support. |
I changed the C-style casts. The other linthub complaints are about lines of code which I didn't touch. |
Great, thank you. :) |
Found a very similar precision issue with sin and cos on Apple's version of Clang. I could make the code a little nicer by creating wrapper functions instead of macros, but I'm pretty sure that doing the calculation at double precision is the best way to fix this problem after all. |
@@ -44,6 +44,9 @@ uint32_t Segments::area() | |||
void Segments::reset() | |||
{ | |||
memset(segment, -1, sizeof(uint32_t) * _area); | |||
for (int i = 0; i<seg_data.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linthub is suggesting to put spaces around the < operator
I was getting wildly different simulation results with Visual C++, using the same seed/parameters that I was using on Linux or OS X. Most of that was caused by the fact that
sizeof(long)
is 4, as opposed to 8 on Clang, GCC, etc.float kc = (seed*seed) % 256;
On this line in particular, the signed 32-bit integer would often overflow into the negatives. Making it explicitly 64-bit keeps behavior consistent across platforms.
That mostly fixes it, but I was still seeing subtle inconsistencies. This is harder to explain. For some reason,
sinf
yields different results when MSVC (2013 or 2015) produces a 64-bit binary. For example, with floats expressed as their raw bytes:sinf(5.516943f)
=0xbf3184cd
on GCC, Clang, and MSVC x86sinf(5.516943f)
=0xbf3184ce
on MSVC x86-64Tried adjusting some flags, but it didn't help. Using the double version of
sin
and then casting back to float gets the correct results. This solution is a little ugly, but it's the only thing that worked.