You can't use %Qf
specifier in the scanf
, you should input the high precision numbers as string, then use strtoflt128
to convert. You also can't use %Qf
specifier in the printf
, use quadmath_snprintf
to converts a __float128
floating-point number into a string, then use printf
with %s
specifier to display it. Here is an example.
#include <stdio.h>
#include <quadmath.h>
int main()
{
char s[256], t[256], mt[256];
printf("enter 3 values for s, t and mt:\n");
scanf("%s %s %s", s, t, mt);
__float128 qs = strtoflt128(s, NULL);
__float128 qt = strtoflt128(t, NULL);
__float128 qmt = strtoflt128(mt, NULL);
quadmath_snprintf(s, 256, "%Qf", qs);
quadmath_snprintf(t, 256, "%Qf", qt);
quadmath_snprintf(mt, 256, "%Qf", qmt);
printf("%s %s %s", s, t, mt);
return 0;
}
run the program:
enter 3 values for s, t and mt:
3.4 4.5 5.6(enter)
3.400000 4.500000 5.600000