directly changing the exponent of a type double
-
Hi, Can anyone tell me how to change the exponent from the type double? Basicly what I want to do is to extract the exponent form: <--------------------all the bytes(8 total)-------------------> (SXXX XXXX) (XXXX MMMM) (MMMM MMMM) (MMMM MMMM) ... (MMMM MMMM) (where x represents the exponent) do some calculations and place it back in. I want to this with a large amount of numbers so I seek a pretty fast way to do it. Anyone got an idea? thx already. greetings, Filip Govaerts Belgium
-
Hi, Can anyone tell me how to change the exponent from the type double? Basicly what I want to do is to extract the exponent form: <--------------------all the bytes(8 total)-------------------> (SXXX XXXX) (XXXX MMMM) (MMMM MMMM) (MMMM MMMM) ... (MMMM MMMM) (where x represents the exponent) do some calculations and place it back in. I want to this with a large amount of numbers so I seek a pretty fast way to do it. Anyone got an idea? thx already. greetings, Filip Govaerts Belgium
double d;
unsigned char * d_layout=reinterpret_cast<unsigned char *>(&d);
//extraction
int exp=int(d_layout[6]>>4)+(int(d_layout[7]&0x7FU)<<4);
//insertion
d_layout[6]&=0x0FU;
d_layout[6]|=(exp&0x0F)<<4;
d_layout[7]&=0x80U;
d_layout[7]|=(exp&0x7F0)>>4;Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
double d;
unsigned char * d_layout=reinterpret_cast<unsigned char *>(&d);
//extraction
int exp=int(d_layout[6]>>4)+(int(d_layout[7]&0x7FU)<<4);
//insertion
d_layout[6]&=0x0FU;
d_layout[6]|=(exp&0x0F)<<4;
d_layout[7]&=0x80U;
d_layout[7]|=(exp&0x7F0)>>4;Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
respect... thx a lot Filip Govaerts