yes I know it's a type I am just asking for the purpose of extracting mantissa sign and exponent why does the sign has to be the type of int_4 and the mantissa has to be int_u8, like that??
Printable View
yes I know it's a type I am just asking for the purpose of extracting mantissa sign and exponent why does the sign has to be the type of int_4 and the mantissa has to be int_u8, like that??
They don't. It's just a matter of choosing an appropriate type big enough to hold it.
The sign can be uint8_t, the exponent can be uint16_t and the mantissa can be uint32_t. These are the smallest possible types to hold all data. That's all.
and does it matter in 64 bit computers there isn't any difference to hold these values because a float is a 32 bit too, but what matters is that the size of int is different in 64 bit right?? like they are 8 byte instead of 4 byte?? am I right??
okay so if there is an assignment that would ask you to use a typedef to assign int_4, int_u4, int_8, and int_u8 into a 64 bit machine.. how would you do this?? assuming it's running on windows
If it's just a 64-bit machine and if you can use existing typedefs, then just do
typedef int_4 int32_t
If you can't, then do a proper sizeof of all types to see their actual size, and then typedef them.
no I want int_4 to be the type not int32_t so I guess you have it reversed
Yes, of course, my mistake.
typedef int32_t int_4;
^^"
Ya know, between the various threads -EquinoX- has created on essentially the same problem, and all of the twists and turns and arguments and explanations, I have to say: I am almost thoroughly confused as to the point of it all.
At best I'd like to think it is about capturing the bit image of an IEEE-754 single-precision floating point value and separating those bits into 3 integral values for sign, exponent, and mantissa. Plus some caveat about trying to be portable.
We've mentioned the usual approaches: wandering the bytes, casting, and a union. All have various portability issues.
Is there someone, anyone, who can give me the nickel summary?
I don't really think I understand 100% either. Just about the capturing the sign, exponent and mantissa from the float and that it will (probably) be done on a 64-bit system.
Why not just print if into a string and all your problems are solved.
"print if"? I guess you mean "printf", or more precisely "sprintf", right? :) Printing "if" into a string would get you a string with, well, "if", which is hardly helpful.
With that method, you won't get the exact exponent and mantissa.
Why not just print it...
I think that's closer, especially since "f" is just under "t".
On whose keyboard? :p Maybe esbo has a Dvorak keyboard . . . .
You're probably right, though.