* Convert a non-negative long value into the bit pattern of * an IEEE-754 float value. */
| 524 | * an IEEE-754 float value. |
| 525 | */ |
| 526 | static uint32_t |
| 527 | encode_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 |
no test coverage detected