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

Function bf_set_float64

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

Source from the content-addressed store, hash-verified

2502}
2503
2504int bf_set_float64(bf_t *a, double d)
2505{
2506 Float64Union u;
2507 uint64_t m;
2508 int shift, e, sgn;
2509
2510 u.d = d;
2511 sgn = u.u >> 63;
2512 e = (u.u >> 52) & ((1 << 11) - 1);
2513 m = u.u & (((uint64_t)1 << 52) - 1);
2514 if (e == ((1 << 11) - 1)) {
2515 if (m != 0) {
2516 bf_set_nan(a);
2517 } else {
2518 bf_set_inf(a, sgn);
2519 }
2520 } else if (e == 0) {
2521 if (m == 0) {
2522 bf_set_zero(a, sgn);
2523 } else {
2524 /* subnormal number */
2525 m <<= 12;
2526 shift = clz64(m);
2527 m <<= shift;
2528 e = -shift;
2529 goto norm;
2530 }
2531 } else {
2532 m = (m << 11) | ((uint64_t)1 << 63);
2533 norm:
2534 a->expn = e - 1023 + 1;
2535#if LIMB_BITS == 32
2536 if (bf_resize(a, 2))
2537 goto fail;
2538 a->tab[0] = m;
2539 a->tab[1] = m >> 32;
2540#else
2541 if (bf_resize(a, 1))
2542 goto fail;
2543 a->tab[0] = m;
2544#endif
2545 a->sign = sgn;
2546 }
2547 return 0;
2548fail:
2549 bf_set_nan(a);
2550 return BF_ST_MEM_ERROR;
2551}
2552
2553/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there
2554 is an overflow and 0 otherwise. */

Callers

nothing calls this directly

Calls 5

bf_set_nanFunction · 0.85
bf_set_infFunction · 0.85
bf_set_zeroFunction · 0.85
clz64Function · 0.85
bf_resizeFunction · 0.85

Tested by

no test coverage detected