From: Joel VanderWerf Date: 2006-07-10T12:42:48+09:00 Subject: Re: Marshal's handling of floats Brian Palmer wrote: > Actually, I'm not terribly concerned with precision, but rather with > speed and size. The application I'm building needs to communicate data > over a wireless network every 100 milliseconds, and it needs to use as > little bandwidth as possible. I was considering just using the Marshal > methods, but Marshal's floating-point representation killed that idea, > though for other Ruby built-in data types it seems to be quite good, > even truncating small integers to bytes and shorts. I've decided that I > only need a couple decimal places of accuracy, though, so I'm just going > to multiply each float by 100 and then convert it to an int. If you don't need to send arbitrary (marshallable) ruby objects, but only fairly well-defined struct-like packets, the you might find this helpful. It's built on top of pack/unpack, but it has a "dsl" flavor and makes it easier to work with odd-length bit fields, for example: http://redshift.sourceforge.net/bit-struct/ (I wrote this for purposes like yours: to send data over a constrained wireless network, and also to communicate easily with non-ruby code, so Marshal was not an option.) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407