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

Add fixed-point math for newbies tutorial #20

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Conversation

avivace
Copy link
Member

@avivace avivace commented Mar 1, 2024

Originally by sasha

int player_fp = 3;

// 1 and 5/8, written verbosely for demonstration purposes
int player_speed = 8 + 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this would be clearer:

int player_speed = (1 << player_fp) + 5;

Or even something like this:

int player_speed = (int)((1 << player_fp) * 1.625);

However, for this, player_fp would need to be const.

In fact, I think that a section on how to generate the initial values from floating point values would be nice. You would need to explain that operations with constant numbers will be optimized by the compiler and that they aren't done at runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a section of converting between float and fixed point would be useful, explaining that this can have a huge impact if done at runtime, and explaining in which cases the compiler will do the conversion at compile time.

@avivace
Copy link
Member Author

avivace commented Mar 20, 2024

I'll merge this as it seems to be stale.. @AntonioND could you implement your suggestions and send another PR?

@avivace avivace merged commit 0a9eafc into main Mar 20, 2024
@AntonioND AntonioND deleted the fixed-point-math-tutorial branch March 20, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants