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

f64-only implementation vs. generic implementation #29

Open
tinko92 opened this issue May 23, 2023 · 0 comments
Open

f64-only implementation vs. generic implementation #29

tinko92 opened this issue May 23, 2023 · 0 comments

Comments

@tinko92
Copy link
Contributor

tinko92 commented May 23, 2023

This library is entirely implemented for f64 and in comments, it is stated that f32 inputs will be converted to f64 without loss of precision. This is true and the provided predicates will be just as correct/robust for f32-values by doing it this way, same for e.g. half-floats or bfloats. For numbers types with higher precision than f64, though, it could return incorrect results.

Numerically, this promotion is not required and afaiu doesn't do anything useful for the computation, except in cases were f32 could underflow/overflow. Shewchuk's algorithms, according to the proofs in his paper, work for all floating-point types that have at least 6 bits of precision for their significands and round-to-even behavior for their basic operations (I think even 4 bits would be sufficient if FMA was used instead of splitting in Two_Product). His implementation allowed switching between types by changing the define for REAL.

So, if e.g. f32 inputs are provided, all computations could be done in f32. This probably wouldn't change anything performance-wise for modern x86 CPUs other than requiring less stack space (I think at most ~16KB rather than ~32KB in insphere adaptive), but it might be more beneficial for other platforms where performance differs between half, single and double precision like GPUs or other CPU architectures than x86. I understand that Rust has a concept of generic functions similar to C++ templates, so, as I understand, the implementation could in principle be made to work for arbitrary floating-point types. I'm new to Rust so I might miss something, though.

Creating a PR to make all provided predicates generic to work for different floating-point types would require some work/learning about rust generics, so I first wanted to ask whether there would be interest from this project in such a PR.

@tinko92 tinko92 changed the title f64-only implementation f64-only implementation vs. generic implementation May 23, 2023
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

No branches or pull requests

1 participant