Neil Schemenauer wrote:
> Basically, write a little C program that exits with 0 or 1 depending
> on double endian-ness.
Here is a medium sized C program. It can probably be coded in a fraction
of the size but this way everybody can understand it. In the case it's
too long for your taste just check if the first or last bit of an
(unsigned int64*)&((double)-1) is 1.
#define BIAS 1023
typedef struct {
unsigned int sign : 1;
unsigned int exp : 11;
unsigned int m1 : 4;
unsigned int m2 : 16;
unsigned int m3 : 16;
unsigned int m4 : 16;
} be_ieee_dbl;
typedef struct {
unsigned int m4 : 16;
unsigned int m3 : 16;
unsigned int m2 : 16;
unsigned int m1 : 4;
unsigned int exp : 11;
unsigned int sign : 1;
} le_ieee_dbl;
/* 1 = little endian IEEE double
* 2 = big endian IEEE double
* 0 = error
*/
int main(void)
{
double dbl = -9.;
le_ieee_dbl *le = (le_ieee_dbl*)&dbl;
be_ieee_dbl *be = (be_ieee_dbl*)&dbl;
if (le->sign == 1 && le->exp-BIAS == 3 && le->m1 == 2 &&
le->m2 == 0 && le->m3 == 0 && le->m4 == 0) {
return 1;
}
if (be->sign == 1 && be->exp-BIAS == 3 && be->m1 == 2 &&
be->m2 == 0 && be->m3 == 0 && be->m4 == 0) {
return 2;
}
return 0;
}
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins