FreeBSD/sys/kern/kern_acct.c
/*
 * Convert a non-negative long value into the bit pattern of
 * an IEEE-754 float value.
 */
Convert a non-negative long value into the bit pattern of
an IEEE-754 float value.
Convert a non - negative long value into the bit pattern of an IEEE - 754 float value .
static uint32_t
encode_long(long val)
{
	int norm_exp;	
	int shift;
	if (val == 0)
		return (0);
	if (val < 0) {
		log(LOG_NOTICE,
		    "encode_long: negative value %ld in accounting record\n",
		    val);
		val = LONG_MAX;
	}
	norm_exp = fls(val) - 1;
	shift = FLT_MANT_DIG - norm_exp - 1;
#ifdef ACCT_DEBUG
	printf("val=%d shift=%d log2(val)=%d\n",
	    val, shift, norm_exp);
	printf("exp=%x mant=%x\n", FLT_MAX_EXP - 1 + exp + norm_exp,
	    ((shift > 0 ? (val << shift) : (val >> -shift)) & MANT_MASK));
#endif
	return (((FLT_MAX_EXP - 1 + norm_exp) << (FLT_MANT_DIG - 1)) |
	    ((shift > 0 ? val << shift : val >> -shift) & MANT_MASK));
}
static uint32_t encode_long ( long val ) { int norm_exp ; int shift ; if ( val == 0 ) return ( 0 ) ; if ( val < 0 ) { log ( LOG_NOTICE , " \n " , val ) ; val = LONG_MAX ; } norm_exp = fls ( val ) - 1 ; shift = FLT_MANT_DIG - norm_exp - 1 ; #ifdef ACCT_DEBUG printf ( " \n " , val , shift , norm_exp ) ; printf ( " \n " , FLT_MAX_EXP - 1 + exp + norm_exp , ( ( shift > 0 ? ( val << shift ) : ( val >> - shift ) ) & MANT_MASK ) ) ; #endif return ( ( ( FLT_MAX_EXP - 1 + norm_exp ) << ( FLT_MANT_DIG - 1 ) ) | ( ( shift > 0 ? val << shift : val >> - shift ) & MANT_MASK ) ) ; }
Convert a non-negative long value into the bit pattern of
 an IEEE-754 float value.
Convert a non - negative long value into the bit pattern of an IEEE - 754 float value .
/* Normalized exponent */