MCPcopy Create free account
hub / github.com/F-Stack/f-stack / encode_long

Function encode_long

freebsd/kern/kern_acct.c:526–550  ·  view source on GitHub ↗

* Convert a non-negative long value into the bit pattern of * an IEEE-754 float value. */

Source from the content-addressed store, hash-verified

524 * an IEEE-754 float value.
525 */
526static uint32_t
527encode_long(long val)
528{
529 int norm_exp; /* Normalized exponent */
530 int shift;
531
532 if (val == 0)
533 return (0);
534 if (val < 0) {
535 log(LOG_NOTICE,
536 "encode_long: negative value %ld in accounting record\n",
537 val);
538 val = LONG_MAX;
539 }
540 norm_exp = fls(val) - 1;
541 shift = FLT_MANT_DIG - norm_exp - 1;
542#ifdef ACCT_DEBUG
543 printf("val=%d shift=%d log2(val)=%d\n",
544 val, shift, norm_exp);
545 printf("exp=%x mant=%x\n", FLT_MAX_EXP - 1 + exp + norm_exp,
546 ((shift > 0 ? (val << shift) : (val >> -shift)) & MANT_MASK));
547#endif
548 return (((FLT_MAX_EXP - 1 + norm_exp) << (FLT_MANT_DIG - 1)) |
549 ((shift > 0 ? val << shift : val >> -shift) & MANT_MASK));
550}
551
552/* FLOAT_CONVERSION_END (Regression testing; don't remove this line.) */
553

Callers 1

acct_processFunction · 0.85

Calls 3

logFunction · 0.70
printfFunction · 0.70
flsFunction · 0.50

Tested by

no test coverage detected