History

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

herman ten brugge committed 1 year ago

Commit cb39bc41 parent 83de5321 file · +18 −1Browse files

Unified · Split

tccpp.c+18−1
@@ -2231,8 +2231,13 @@ static void parse_string(const char *s, int len) · 2230 unmodified lines
22312231 }
22322232 }
22332233
2234−/* we use 64 bit numbers */
2234+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
2235+/* we use 64 bit (52 needed) numbers */
22352236 #define BN_SIZE 2
2237+#else
2238+/* we use 128 bit (64/112 needed) numbers */
2239+#define BN_SIZE 4
2240+#endif
22362241
22372242 /* bn = (bn << shift) | or_val */
22382243 static void bn_lshift(unsigned int *bn, int shift, int or_val)
@@ -2261,7 +2266,11 @@ static void parse_number(const char *p) · 22 unmodified lines
22612266 int b, t, shift, frac_bits, s, exp_val, ch;
22622267 char *q;
22632268 unsigned int bn[BN_SIZE];
2269+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
22642270 double d;
2271+#else
2272+ long double d;
2273+#endif
22652274
22662275 /* number */
22672276 q = token_buf;
@@ -2374,8 +2383,16 @@ static void parse_number(const char *p) · 106 unmodified lines
23742383
23752384 /* now we can generate the number */
23762385 /* XXX: should patch directly float number */
2386+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
23772387 d = (double)bn[1] * 4294967296.0 + (double)bn[0];
23782388 d = ldexp(d, exp_val - frac_bits);
2389+#else
2390+ d = (long double)bn[3] * 79228162514264337593543950336.0L +
2391+ (long double)bn[2] * 18446744073709551616.0L +
2392+ (long double)bn[1] * 4294967296.0L +
2393+ (long double)bn[0];
2394+ d = ldexpl(d, exp_val - frac_bits);
2395+#endif
23792396 t = toup(ch);
23802397 if (t == 'F') {
23812398 ch = *p++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t