Is it guaranteed that the binary representation of singles, doubles, and floats will be identical to the original after serializing and deserializing?
I doubt it very much.
Try it using the DataContractSerializer
instead. The XmlSerializer
isn't being actively maintained.
No you can't assume that. Eventually, something will get rounded during serialization and your number will be off. Accurately representing a floating point number in a binary system is difficult at best, and at times is impossible.
http://usenix.org/publications/login/2005-02/pdfs/mccluskey.pdf
You'll need to read this thread to get a feel for what accuracy means when you work with floating point numbers. Whatever happens to them when they get serialized to XML really doesn't matter much. It will be accurate enough. Use the decimal type if you are uncomfortable about this kind of fuzziness. You shouldn't be, that's how they work.