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

Support long double #349

Open
edsko opened this issue Jan 8, 2025 · 1 comment
Open

Support long double #349

edsko opened this issue Jan 8, 2025 · 1 comment

Comments

@edsko
Copy link
Collaborator

edsko commented Jan 8, 2025

This is non-trivial, as there is no native support for long double in the RTS. Opening this ticket mostly just to track the fact that we're not supporting long double for now.

@edsko edsko added this to the 4: Additional features milestone Jan 8, 2025
@TravisCardwell
Copy link
Collaborator

My comments from #293, reorganized:

Foreign.C.Types does not define a long double type, perhaps because it is implementation-specific. The standard (since C89) just says that it needs to be at least a large as double. My understanding is that the implementation may differ in different libraries/compilers since the standard does not have exact specifications for the type, not just per architecture. Perhaps implementations are consistent in practice...

Not supporting long dobule means that we are unable to implement some things in the standard library. Examples:

  • typedef struct { long long __ll; long double __ld; } max_align_t;
  • float_t is an architecture-dependent type. For example, it is a long double on i386 and a float on x86_64.

Here is a GHC issue regarding long double: #3353

The long-double package implements support for x86_64, aarch64, arm, and i386 architectures.

The x86_64 implementation matches my test (using GCC and GNU libc):

sizeof(float):         4
alignof(float):        4
sizeof(double):        8
alignof(double):       8
sizeof(long double):  16
alignof(long double): 16
Source
#include <stdalign.h>
#include <stdio.h>

int main(void) {
  printf("sizeof(float):        % 2zu\n", sizeof(float));
  printf("alignof(float):       % 2zu\n", alignof(float));
  printf("sizeof(double):       % 2zu\n", sizeof(double));
  printf("alignof(double):      % 2zu\n", alignof(double));
  printf("sizeof(long double):  % 2zu\n", sizeof(long double));
  printf("alignof(long double): % 2zu\n", alignof(long double));
  return 0;
}

As mentioned in the GHC issue, an alternative approach would be to define an opaque type and only support pointers. That would limit what we can support, though, which may be problematic.

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

2 participants