LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-04-2006, 08:09 AM   #1
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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
0 1      8 9                    31
where S is the sign bit
E are the exponent
and M the mantissa
whichs gives the forumla
Code:
(-1)^S * 1.M * 2^E-127
The standard C header file "math" gives a function for calculating this,ldexp(), yet the result I get is not the exspected one.
For the floating point number of 3.7 the binary representation is:
Code:
0 10000000 11011001100110011001101
S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM
the resulting sum should be
Code:
1 * ldexp(1.11011001100110011001101,128 -127)
but gives the result 2.22022?
Can someone see what I am doing wrong?
Cheers.
 
Old 02-04-2006, 01:57 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Original Poster
Rep: Reputation: Disabled
oops

Code:
1 * ldexp(1.11011001100110011001101,128 -127)
made a very silly mistake
it should be
Code:
1.0+(1/2)+(1/4)+0+(1/16)...etc
and theres a drop in precision between 0.1 and 0.2 which I dont think is acceptable. ;(

<edit>
although after doing this I have come accross some info which is what i was trying to do
Quote:
If you know that three of your floats are components of a normalized vector (i.e. they can only be between [-1,1]), and you want full float precision, then you can bump the float into the range of +-[1,2] and safely ignore the entire exponent block for those floats (8 out of 32 bits each) during network transmission. That's a whole byte lopped off for each of those floats, with no loss of precision. If you ARE willing to lose precision, you can save even more. Once again, the key here is to know your data.
</edit>

Last edited by dmail; 02-04-2006 at 02:34 PM.
 
Old 02-05-2006, 01:52 AM   #3
ppanyam
Member
 
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
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!
 
Old 02-05-2006, 05:10 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating point exception hemk76 Linux - Software 1 05-06-2005 11:49 PM
floating point multiplication irfanhab Programming 0 12-23-2004 10:13 PM
modulo of 2 floating point numbers? jenna_h Programming 6 09-24-2004 09:39 AM
managing floating point vince_2x Linux - General 2 09-21-2004 09:05 PM
floating point numbers in java spyghost Programming 8 09-06-2003 06:21 PM


All times are GMT -5. The time now is 04:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration