Calculate hex floating point with 128 bits instead of 64 bits.

This commit is contained in:
herman ten brugge
2025-05-27 07:36:33 +02:00
parent 83de532563
commit cb39bc4cac

19
tccpp.c
View File

@@ -2231,8 +2231,13 @@ static void parse_string(const char *s, int len)
}
}
/* we use 64 bit numbers */
#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
/* we use 64 bit (52 needed) numbers */
#define BN_SIZE 2
#else
/* we use 128 bit (64/112 needed) numbers */
#define BN_SIZE 4
#endif
/* bn = (bn << shift) | or_val */
static void bn_lshift(unsigned int *bn, int shift, int or_val)
@@ -2261,7 +2266,11 @@ static void parse_number(const char *p)
int b, t, shift, frac_bits, s, exp_val, ch;
char *q;
unsigned int bn[BN_SIZE];
#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
double d;
#else
long double d;
#endif
/* number */
q = token_buf;
@@ -2374,8 +2383,16 @@ static void parse_number(const char *p)
/* now we can generate the number */
/* XXX: should patch directly float number */
#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
d = (double)bn[1] * 4294967296.0 + (double)bn[0];
d = ldexp(d, exp_val - frac_bits);
#else
d = (long double)bn[3] * 79228162514264337593543950336.0L +
(long double)bn[2] * 18446744073709551616.0L +
(long double)bn[1] * 4294967296.0L +
(long double)bn[0];
d = ldexpl(d, exp_val - frac_bits);
#endif
t = toup(ch);
if (t == 'F') {
ch = *p++;