bellard / quickjs

Public repository of the QuickJS Javascript Engine.
https://bellard.org/quickjs
Other
8.55k stars 895 forks source link

Fix compiling with undefined to `bfdec_normalize_and_round` #354

Open HarlonWang opened 2 months ago

HarlonWang commented 2 months ago

A compilation error occurs when without CONFIG_BIGNUM.

quickjs/libbf.c:3110: error: undefined reference to 'bfdec_normalize_and_round'

Because there's no conditional handling here.

/* enable it to check the multiplication result */
//#define USE_MUL_CHECK
#ifdef CONFIG_BIGNUM
/* enable it to use FFT/NTT multiplication */
#define USE_FFT_MUL
/* enable decimal floating point support */
#define USE_BF_DEC
#endif

static int bf_atof_internal(...){
    if (is_dec) {
        a->expn = expn + int_len;
        a->sign = is_neg;
        // we need to check if USE_BF_DEC is enabled.
        ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);
    } else if (radix_bits) {
        ...
    }
   ...

I made a simple fix.

#ifdef USE_BF_DEC
    if (is_dec) {
        a->expn = expn + int_len;
        a->sign = is_neg;
        ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);
    } else
#endif
    if (radix_bits) {

Related issues: https://github.com/bellard/quickjs/issues/241 https://github.com/bellard/quickjs/issues/326