MCPcopy Create free account
hub / github.com/Snapchat/Valdi / bf_set_overflow

Function bf_set_overflow

third-party/quickjs/src/quickjs/libbf.c:465–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

463}
464
465static int bf_set_overflow(bf_t *r, int sign, limb_t prec, bf_flags_t flags)
466{
467 slimb_t i, l, e_max;
468 int rnd_mode;
469
470 rnd_mode = flags & BF_RND_MASK;
471 if (prec == BF_PREC_INF ||
472 rnd_mode == BF_RNDN ||
473 rnd_mode == BF_RNDNA ||
474 rnd_mode == BF_RNDA ||
475 (rnd_mode == BF_RNDD && sign == 1) ||
476 (rnd_mode == BF_RNDU && sign == 0)) {
477 bf_set_inf(r, sign);
478 } else {
479 /* set to maximum finite number */
480 l = (prec + LIMB_BITS - 1) / LIMB_BITS;
481 if (bf_resize(r, l)) {
482 bf_set_nan(r);
483 return BF_ST_MEM_ERROR;
484 }
485 r->tab[0] = limb_mask((-prec) & (LIMB_BITS - 1),
486 LIMB_BITS - 1);
487 for(i = 1; i < l; i++)
488 r->tab[i] = (limb_t)-1;
489 e_max = (limb_t)1 << (bf_get_exp_bits(flags) - 1);
490 r->expn = e_max;
491 r->sign = sign;
492 }
493 return BF_ST_OVERFLOW | BF_ST_INEXACT;
494}
495
496/* round to prec1 bits assuming 'r' is non zero and finite. 'r' is
497 assumed to have length 'l' (1 <= l <= r->len). Note: 'prec1' can be

Callers 3

__bf_roundFunction · 0.85
bf_powFunction · 0.85

Calls 5

bf_set_infFunction · 0.85
bf_resizeFunction · 0.85
bf_set_nanFunction · 0.85
limb_maskFunction · 0.85
bf_get_exp_bitsFunction · 0.85

Tested by

no test coverage detected