Floating data types

Are floating(double and long double too) data types the same on all
platforms? That is do they all have the same mantissa, exponent,
endianess… I noticed SDL_net doesn’t have any conversion methods for
sending floats to machines of different endianess.

Also SDLnet uses right shifting to convert numbers from the machines
endianess to nbo. Why not use a macro based on the machines endianess,
then if it’s big endian time wouldn’t be wasted shifting the number to a
format it’s already in.

http://www.mongeese.org

Garrett Banuk wrote:

Are floating(double and long double too) data types the same on all
platforms? That is do they all have the same mantissa, exponent,
endianess… I noticed SDL_net doesn’t have any conversion methods for
sending floats to machines of different endianess.

Also SDLnet uses right shifting to convert numbers from the machines
endianess to nbo. Why not use a macro based on the machines endianess,
then if it’s big endian time wouldn’t be wasted shifting the number to a
format it’s already in.

http://www.mongeese.org

They might be the same. I don’t think there’s any guarantee that they
will be. I used the following macros in my book:

#include <netinet/in.h> /* htonl and ntohl macros /
#define DOUBLE_TO_NET(dbl) (htonl((Sint32)((double)dbl
65536.0)))
#define NET_TO_DOUBLE(net) ((double)ntohl(net)/65536.0)

Then just send doubles as Sint32’s. You’ll lose precision, but you can
probably live with it.
You can also use SDL’s byteswapping macros instead of htonl and ntohl.

-John–
Underfull \account (badness 10000) has occurred while \spend is active
John R. Hall - Student, Georgia Tech - Contractor, Loki Software

Are floating(double and long double too) data types the same on all
platforms? That is do they all have the same mantissa, exponent,
endianess… I noticed SDL_net doesn’t have any conversion methods for
sending floats to machines of different endianess.

2 issues: byte order and fp format. Most contemporary machines use
IEEE floats so you can safely spec that in a protocol. Use either 32
or 64 bit floats; oddball ones like 80 (intel) or 128 (sun) are out,
so are ancient stuff like ibm 360/VAX/Cray fp formats. You can
probably use the ordinary byte order macros to convert endianness —
this is not guaranteed but true in reality

Mensaje citado por: Mattias Engdeg?rd :

Are floating(double and long double too) data types the same on
all

platforms? That is do they all have the same mantissa, exponent,
endianess… I noticed SDL_net doesn’t have any conversion methods
for> >sending floats to machines of different endianess.

2 issues: byte order and fp format. Most contemporary machines use
IEEE floats so you can safely spec that in a protocol. Use either 32
or 64 bit floats; oddball ones like 80 (intel) or 128 (sun) are out,
so are ancient stuff like ibm 360/VAX/Cray fp formats. You can
probably use the ordinary byte order macros to convert endianness


this is not guaranteed but true in reality

I know that Age of Kings are having a lot of problems due to float
point values, as not all the system ( and speaking on x86 system only
:-> ) compute the number in the same way.

To compute the value and having the same result on both system you are
going to need:
a) Same precision
b) Non buggy FPU
c) Good luck

But for common things there shouldn’t be many problems.