/* linear interpolation between powers of 2 */ static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits) { unsigned fract = x & ~(~0 << fract_bits); x >>= fract_bits; x = 1 << x; x += (x * fract) >> fract_bits; return x; } i came across function, not figure out does. result returns? tried arguments, hardly found clues.is there explanation?
after tips @doynax , referenced link, https://en.wikipedia.org/wiki/half-precision_floating-point_format.
i figured out how worked.
a x formed 2 parts, 1 (high part x >>= fract_bits in function) exponent (pow of 2), , 1 (low part fract = x & ~(~0 << fract_bits) in function) fraction part (also pow of 2). unless high part zeros, implicitly represent 1 (x = 1<<x). final part x += (x * fract) >> fract_bits means 1+mantissa * exponent part. it's method encode float point 2bytes data type.
Comments
Post a Comment