# Thread: Extracting an exponent without knowing the size of the mantissa & exponent

1. ## Extracting an exponent without knowing the size of the mantissa & exponent

I've come up with this:
Code:
```typedef union _pawkfdunion
{
pawkfd num;
pawku  val;
pawcu  raw[sizeof(pawkfd)];
} pawkfdunion;

static pawvu pawkfd_man_len = 0;

PAWSTR_API pawvu    pawkfdexp( pawkfd src )
{
pawvu i = pawkfd_man_len;
pawkfdunion kfd = {0};
if ( !i )
{
#	ifdef PAWKFD_INF
kfd.num = PAWKFD_INF;
kfd.num--;
#	else
kfd.num = PAWKFD_MAX;
#	endif
kfd.raw[sizeof(pawkfd)-1] &= PAWCD_MAX;
for ( ; kfd.val & 1u; ++i, kfd.val >>= 1 );
pawkfd_man_len = i;
}
kfd.num = src;
kfd.raw[sizeof(pawkfd)-1] &= PAWCD_MAX;
return (kfd.val >> i);
}```
Assume pawku means __uint128, pawkfd means _Float128x & pawcu always means unsigned char, does anyone see any potential issues with this?

2. Originally Posted by awsdert
]
Assume pawku means __uint128, pawkfd means _Float128x & pawcu always means unsigned char, does anyone see any potential issues with this?
What does it do with denormalized numbers? Does it handles non-numbers like infinity?

3. Originally Posted by hamster_nz
What does it do with denormalized numbers? Does it handles non-numbers like infinity?
This function is just to extract the exponent so that I can construct a string from the float, because I'm doing this for a custom library that is to work with or without libc I have to avoid relying on external libraries which in all likelihood rely on libc anyways, in other words I have to rely ONLY on what the system and the compiler provide me with, unfortunately I can't find any predefines or builtins or otherwise that would provide me the exponent & mantissa width directly so calculating it with the assumption that the exponent is one lower than it's max value is the only way I can think of to obtain the mantissa length and in turn the exponent width which in turn allows me to get the exponent itself

Popular pages Recent additions