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

Fixed-point game calculations are ugly and inflexible #1

Closed
tmewett opened this issue Sep 3, 2019 · 4 comments
Closed

Fixed-point game calculations are ugly and inflexible #1

tmewett opened this issue Sep 3, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@tmewett
Copy link
Owner

tmewett commented Sep 3, 2019

The fixed-point code is ugly, error-prone and difficult to modify; it uses hard-coded look-up tables.

It may be possible to revert to using floating-point and improve its portability. There are some fp compiler options in GCC like -fexcess-precision=standard, and some targets accept -mieee or -mieee-fp to improve portability of fp calculations. The problem is that C doesn't guarantee its fp representations conform to IEEE 754.

Alternatively the fixed-point could be cleaned up, possibly with code generation.

@tmewett
Copy link
Owner Author

tmewett commented Sep 4, 2019

Assuming we can convince the compiler to conform to IEEE, the only way I can currently see out-of-sync errors occuring is due to accumulated errors when modifying floats. For example, if non-recorded inputs somehow temporarily modify floating-point state variables, by say adding and then taking away a value, then the result may be slightly different to the original. But this would require careful inspection of the code.

@tmewett
Copy link
Owner Author

tmewett commented Sep 13, 2019

It may be possible to instead implement a reasonable fixed-point pow function. There is a technique where you expand the fractional part of the exponent as a sum of negative powers of 2, (i.e. 1/2 + 1/4 + 1/8 + ...) and use square roots to compute the result. However this would be slower than both lookup tables and floating point.

@tmewett tmewett added the enhancement New feature or request label Sep 16, 2019
@tmewett
Copy link
Owner Author

tmewett commented Oct 12, 2019

A fixed-point pow was added in 2e7a8a0. Rewriting the lookup tables with this function will make things a lot tidier.

@tmewett
Copy link
Owner Author

tmewett commented Nov 17, 2019

Closing this as the tools are available to remedy it; things will be refactored as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant