c - In Sun's libm, what does *(1+(int*)&x) do (where x is of type double)? -


the expression

#define __hi(x) *(1+(int*)&x) 

is defined in sun's math library, in fdlibm.h. used in programs of sun's math library, e.g., in its implementation of sin(x)

    double y[2],z=0.0;     int n, ix;      /* high word of x. */     ix = __hi(x);      /* |x| ~< pi/4 */     ix &= 0x7fffffff;     if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); 

in code above, variable x of type double. can 1 explain me syntax expression in __hi(x). the readme of sun's library says __hi(x)

"the high part of double x (sign,exponent,the first 21 significant bits)".

i not understand syntax of *(1+(int*)&x), , why corresponds x 's higher part. clarification?

this:

*(1+(int*)&x) 

means: take address of x (&x), cast pointer-to-int (int*), add 1, , dereference resulting pointer. assuming sun using this format, means value in memory looks like:

<sign (1 bit)><exponent (11 bits)><significand (52 bits)> 

if sizeof(int) 32 bits, find location of double in memory, increment pointer next int, contains sign, exponent, , first 21 bits of number.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -