fromfp not work with tgmath for long double argument
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
fromfp() with a long double argument along with does not call fromfpl().
This is for clang 22.1.8-1 and glibc 2.43-6 and gcc 16.1.1-2 on Intel x64 Fedora Linux 44
This code works fine with gcc, but fails for clang.
The following code shows the problem.
```c
#define __STDC_WANT_IEC_60559_EXT__ 1
#define __STDC_WANT_DEC_FP__ 1
#define __STDC_WANT_IEC_60559_DFP_EXT__ 1
#include
#include
#include
#include
#include
#include
int main(void){
long double ld, res1, res2;
int flags1, flags2;
#define str(s) # s
#define xstr(s) str(s)
(void)printf("fromfp is %s is %s\n", str(fromfp), xstr(fromfp(0,0,0)));
ld = 1.L - LDBL_EPSILON;
feclearexcept(FE_ALL_EXCEPT);
res2 = (fromfpl)( ld, FP_INT_TOWARDZERO, 64 ); /* specific */
flags2 = fetestexcept( FE_ALL_EXCEPT );
feclearexcept(FE_ALL_EXCEPT);
res1 = fromfp( ld, FP_INT_TOWARDZERO, 64 ); /* generic */
flags1 = fetestexcept( FE_ALL_EXCEPT );
(void)printf("flags1: %#x\n", flags1);
(void)printf("flags2: %#x\n", flags2);
(void)printf("res1: %.0Lf=f(%.20Lf)\n", res1, ld);
(void)printf("res2: %.0Lf=f(%.20Lf)\n", res2, ld);
(void)fflush( stdout );
assert( res1 == res2 );
assert( FE_INEXACT != flags1 );
assert( FE_INEXACT != flags2 );
assert( 0 == flags1 );
assert( 0 == flags2 );
return 0;
}
```
Contributor guide
Research direction
Start by compiling the provided reproducer with the reported Clang, glibc, and GCC versions and compare the generic fromfp call with the explicit fromfpl call. Trace Clang's handling of fromfp through for a long double argument; done means the generic call selects fromfpl and the reproducer's result and floating-point exception assertions pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100