Skip to content

How to handle long doubles in libffi-rs? #131

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

Open
emiltayl opened this issue May 5, 2025 · 3 comments
Open

How to handle long doubles in libffi-rs? #131

emiltayl opened this issue May 5, 2025 · 3 comments
Labels

Comments

@emiltayl
Copy link
Contributor

emiltayl commented May 5, 2025

I created a pull request to enable long double on all targets as a long double type has been defined for all targets since libffi v3.4.6. However, I have some questions on how long doubles should be handled for this project, so thought it best to open an issue.

The problem is that long double is not supported by Rust on most targets. On some targets it is equivalent to a double, however it is also a f80 on x86(_64) and f128 on a variety of platforms. f128 is available in nightly, but I do not think there are any concrete plans for a f80 in Rust.

This makes it a little tricky and potentially error prone to test for long double support properly, and there are no tests using it at the moment. I am not sure what the best way to handle long double in a Rust project is.

Should long double be included in libffi-rs at all? Or should it perhaps be available only in the raw and low modules due to the lack of native Rust support for the type? I am not saying that any of these are the correct answer, perhaps it is best to keep it as it is now, but I think it is worth to consider this.

If long double is kept, should there be tests for it on targets where this is possible? This does require some extra maintenance to make sure that tests are kept up-to-date and accurately tests for long double support where possible. The alternative is to keep it as it is today, available but not tested, requiring users of libffi-rs to perform their own tests to make sure it works. Searching GitHub, there does not seem to be a lot of use of long double with libffi-rs, which is not strange since the type is not generally supported by Rust.

@arihant2math
Copy link
Collaborator

I think that it is a good idea to keep the long double at the raw/low levels only, in general. Long double is f64 on arm and c_double on windows. I’d prefer just to not support f80/f128 long double for now. If f128 gets stabilized (it is rather close from what I know) then we could add support for that as well. Testing would be much simpler if we keep it this way.

@arihant2math
Copy link
Collaborator

Specifically 80-bit long doubles only occur on intel based architectures due to their FPU size of 80-bits.

@arihant2math
Copy link
Collaborator

Related: rust-lang/rust-bindgen#1549

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

No branches or pull requests

2 participants