IEEE 754 floating point numbers
I have been looking at an optimised way of sending the value of floating point numbers over an network in a cross platform way. So that if sending a normlised vector then there is no need to send 32 bits for each the i j and k values as this could be compressed depending on the accuracy required.
Floating points are standardised by IEEE 754 as: Code:
S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM E are the exponent and M the mantissa whichs gives the forumla Code:
(-1)^S * 1.M * 2^E-127 For the floating point number of 3.7 the binary representation is: Code:
0 10000000 11011001100110011001101 Code:
1 * ldexp(1.11011001100110011001101,128 -127) Can someone see what I am doing wrong? Cheers. |
oops
Code:
1 * ldexp(1.11011001100110011001101,128 -127) it should be Code:
1.0+(1/2)+(1/4)+0+(1/16)...etc <edit> although after doing this I have come accross some info which is what i was trying to do ;) Quote:
|
If you go ahead with your plan of optimized data transfer across the network, how much are you gaining? You have to write code for optimized compression on one side and decompression on the other side( if I can use those words), then test them, test them and test them... Then something changes and it doesnt fit your scheme of things... May the data needs to be read with some other application..
Yes such things were needed in olden days when systems were not so rich in resources. But nowadays? It is better to stick to standards, at least for atomic level data! Maybe I am wrong, but I cant get myself to do it right now. And I do handle terabytes of data! |
I should point out this is for a fast paced game, so time is critical and the network is the bottle neck.
For a normalised 3D vector there is a saving of 3 bytes, chopping a byte of each float. The game has a network thread that doesn't convert back to floats or vise vesra just reads in the data and passes to the game(if needed) or gets the data from the game, so theres no time taken away from the network thread to interpret the data. |
All times are GMT -5. The time now is 03:57 PM. |