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

math: Add a function for calculating the arcsin #2

Closed
wants to merge 1 commit into from

Conversation

FintasticMan
Copy link
Member

@FintasticMan FintasticMan commented Apr 4, 2023

The function is based on a binary search. It performs a binary search, and then does a naive interpolation, because the inputs aren't necessarily in the lookup table.

It has a slight "issue" where if arg is -32768 it accesses a value out of bounds, which could be mitigated by adding an if statement to the beginning of the function that just returns -90 if arg is -32768. I don't think that's necessary, because the user of the function should just make sure that the inputs are within the range [-32767, 32767].

It's necessary for a better algorithm I'm working on for raise to wake.

The function is based on a binary search.
@Riksu9000
Copy link
Contributor

Why not implement this function in InfiniTime?

@FintasticMan
Copy link
Member Author

The only reason I don't want to implement it in InfiniTime is because I'd have to duplicate the 91-element lookup table. It saves 182 bytes by not duplicating it.

@Riksu9000
Copy link
Contributor

I think you can implement it by accessing the array through the _lv_trigo_sin() function.

@FintasticMan
Copy link
Member Author

That is possible, but I'd be concerned about the overhead added by the the branches and modulo. I can try it anyway though.

@FintasticMan
Copy link
Member Author

It seems that it works well enough implementing this in InfiniTime. See InfiniTimeOrg/InfiniTime#826.

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