diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2025-03-19 11:59:47 +0100 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2025-03-19 11:59:47 +0100 |
commit | 5a16c0c1eba084742ed328eff75b9e886e63d166 (patch) | |
tree | 0445b13748437d209fae02938124acc81a40ec8d /quickjs.c | |
parent | 6de88859e7fdb8c6418e1033e75ca4900e022b51 (diff) | |
download | quickjs-5a16c0c1eba084742ed328eff75b9e886e63d166.tar.gz quickjs-5a16c0c1eba084742ed328eff75b9e886e63d166.zip |
fixed JS_DumpValue() for BigInt
Diffstat (limited to 'quickjs.c')
-rw-r--r-- | quickjs.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -12870,19 +12870,32 @@ static __maybe_unused void JS_DumpValueShort(JSRuntime *rt, case JS_TAG_FLOAT64: printf("%.14g", JS_VALUE_GET_FLOAT64(val)); break; -#if 0 - /* XXX: TODO */ + case JS_TAG_SHORT_BIG_INT: + printf("%" PRId64 "n", (int64_t)JS_VALUE_GET_SHORT_BIG_INT(val)); + break; case JS_TAG_BIG_INT: { - JSBigFloat *p = JS_VALUE_GET_PTR(val); - char *str; - str = bf_ftoa(NULL, &p->num, 10, 0, - BF_RNDZ | BF_FTOA_FORMAT_FRAC); - printf("%sn", str); - bf_realloc(&rt->bf_ctx, str, 0); + JSBigInt *p = JS_VALUE_GET_PTR(val); + int sgn, i; + /* In order to avoid allocations we just dump the limbs */ + sgn = js_bigint_sign(p); + if (sgn) + printf("BigInt.asIntN(%d,", p->len * JS_LIMB_BITS); + printf("0x"); + for(i = p->len - 1; i >= 0; i--) { + if (i != p->len - 1) + printf("_"); +#if JS_LIMB_BITS == 32 + printf("%08x", p->tab[i]); +#else + printf("%016" PRIx64, p->tab[i]); +#endif + } + printf("n"); + if (sgn) + printf(")"); } break; -#endif case JS_TAG_STRING: { JSString *p; |