On Mar 18, 10:11 pm, julvr <nos...@ulvr.comwrote:
Quote:
Is the encoding for float platform independent? That is, if I
take the four bytes, stick them into an ethernet packet send
them to another machine, then (after endian swapping and
alignment), set a float pointer to point at those four bytes,
will I get the same value? It seems to work on the plaforms I
have, but this is suppose to work for any machine types -- so
I guess my question is, is the encoding of float standardized?
|
Yes and no. There is a "standard" encoding, but it's
independant of the C++ standard, and not used everywhere.
Off hand, I know of at least four different encodings in use on
machines being sold today. Most, however, are used on
mainframes, for historical reasons: if you're only goal is to
communicate between mainstream Unix machines and Windows, then
you can probably count on IEEE format: type pun your float to a
uin32_t, and transmit that. (Note that even integers have
different formats on some machines: 36 bit 1's complement, or 48
bit signed magnitude, at least, are still in use today. Again,
however, not everyone necessarily has to worry about these.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34