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

Make types generic #35

Open
bojohnson5 opened this issue Jan 23, 2025 · 3 comments
Open

Make types generic #35

bojohnson5 opened this issue Jan 23, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@bojohnson5
Copy link

I’m wondering what it would look like to make the types generic for any floating point number rather than having f64 hardcoded. Would implementing generics using num-traits be viable? That’s a pull request I could work on if it makes sense.

@ethanbarry
Copy link
Contributor

Well, I'm not sure whether algorithms which are stable for 64-bit floats are necessarily stable for 32-bit floats. It seems like stepping down the precision shouldn't cause an issue, but floating point errors can sometimes be counter-intuitive. I guess we'd have to test it!

Unfortunately, I've been quite busy in the last couple of weeks with a new job, and I know @Axect has had a lot on his plate for some time now. :( It sounds like a great feature to have, though. 32-bit arithmetic would allow this library to support hardware without 64-bit FPUs or software emulation.

@bojohnson5
Copy link
Author

Cool, I'll see about implementing this and testing it out when I have time, too! Thanks!

@Axect
Copy link
Owner

Axect commented Feb 6, 2025

Hello @bojohnson5 ,
Thank you for your interest in Puruspe! I'd like to share some context about this.

When I initially developed Puruspe, the primary focus was on implementing special functions with sufficient precision, which is why I chose to work exclusively with f64. However, I completely agree that extending support to f32 through generic implementation would be a valuable addition to the library, particularly for use cases involving hardware without 64-bit FPUs or where software emulation is needed.

As @ethanbarry correctly pointed out, we need to be careful about numerical stability when working with different floating-point precisions. While implementing generics using num-traits is technically feasible, we would need to develop tailored test suites specifically for f32 to ensure the algorithms maintain their stability and accuracy at lower precision.

This would be a significant and welcome contribution to Puruspe. If you're interested in working on this feature, I'd be happy to provide guidance and review the implementation. We should pay particular attention to:

  1. Implementing comprehensive test cases for f32
  2. Verifying numerical stability across different precision levels
  3. Documenting any precision-specific considerations or limitations

Let me know if you'd like to proceed with this enhancement, and we can discuss the implementation details further.

@Axect Axect added the enhancement New feature or request label Feb 6, 2025
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

3 participants