c - get the float number's exponents -


this question has answer here:

i started learning floating point , know sme stuff. i'm still confused mantissa... can explain me how can exp part of float. sorry if that's super stupid , basic question having hard time understanding it...

also how implement following function... implementation wrong. how do it?

// extract 8-bit exponent field of single precision // floating point number f , return unsigned byte unsigned char get_exponent_field(float f) { // todo: code here. int bias = 127; int expp = (int)f; unsigned char e = expp-bias;  return e; } 

if want extract ieee-754 single precision exponent float value (in excess 127 notation), can use float functions, or can use simple union shift , mask same:

unsigned float_getexp (float f) {     union {         unsigned u;         float f;     } uf;     uf.f = f;     return (uf.u >> 23) & 0xff; } 

if want actual exponent bias (i.e. number of places mantissa decimal shifted during normalization prior hidden bit removal), subtract 127 value returned, or if want value returned, subtract before return.

give try , let me know if have questions. (note: type should unsigned exponent, instead of int have).


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -