([BinaryCStream -encodeValueOfCType:at:withName:]): Encode the

exponent as a short, not an int.
([BinaryCStream -decodeValueOfCType:at:withName:]): Likewise, decoding.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1291 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-03-30 00:50:30 +00:00
parent 4bb93b1005
commit 064b35b0af

View file

@ -206,16 +206,19 @@ static BOOL debug_binary_coder;
case _C_FLT: case _C_FLT:
{ {
volatile double value; volatile double value;
int exp, mantissa; int exponent, mantissa;
short exponent_encoded;
value = *(float*)d; value = *(float*)d;
/* Get the exponent */ /* Get the exponent */
value = frexp (value, &exp); value = frexp (value, &exponent);
exponent_encoded = exponent;
NSParameterAssert (exponent_encoded == exponent);
/* Get the mantissa. */ /* Get the mantissa. */
value *= FLOAT_FACTOR; value *= FLOAT_FACTOR;
mantissa = value; mantissa = value;
assert (value - mantissa == 0); assert (value - mantissa == 0);
/* Encode the value as its two integer components. */ /* Encode the value as its two integer components. */
WRITE_SIGNED_TYPE (&exp, int, htonl); WRITE_SIGNED_TYPE (&exponent_encoded, short, htons);
WRITE_SIGNED_TYPE (&mantissa, int, htonl); WRITE_SIGNED_TYPE (&mantissa, int, htonl);
break; break;
} }
@ -223,10 +226,13 @@ static BOOL debug_binary_coder;
case _C_DBL: case _C_DBL:
{ {
volatile double value; volatile double value;
int exp, mantissa1, mantissa2; int exponent, mantissa1, mantissa2;
short exponent_encoded;
value = *(double*)d; value = *(double*)d;
/* Get the exponent */ /* Get the exponent */
value = frexp (value, &exp); value = frexp (value, &exponent);
exponent_encoded = exponent;
NSParameterAssert (exponent_encoded == exponent);
/* Get the first part of the mantissa. */ /* Get the first part of the mantissa. */
value *= FLOAT_FACTOR; value *= FLOAT_FACTOR;
mantissa1 = value; mantissa1 = value;
@ -235,7 +241,7 @@ static BOOL debug_binary_coder;
mantissa2 = value; mantissa2 = value;
assert (value - mantissa2 == 0); assert (value - mantissa2 == 0);
/* Encode the value as its three integer components. */ /* Encode the value as its three integer components. */
WRITE_SIGNED_TYPE (&exp, int, htonl); WRITE_SIGNED_TYPE (&exponent_encoded, short, htons);
WRITE_SIGNED_TYPE (&mantissa1, int, htonl); WRITE_SIGNED_TYPE (&mantissa1, int, htonl);
WRITE_SIGNED_TYPE (&mantissa2, int, htonl); WRITE_SIGNED_TYPE (&mantissa2, int, htonl);
break; break;
@ -358,14 +364,15 @@ static BOOL debug_binary_coder;
case _C_FLT: case _C_FLT:
{ {
int exp, mantissa; short exponent;
int mantissa;
double value; double value;
/* Decode the exponent and mantissa. */ /* Decode the exponent and mantissa. */
READ_SIGNED_TYPE (&exp, int, ntohl); READ_SIGNED_TYPE (&exponent, short, ntohs);
READ_SIGNED_TYPE (&mantissa, int, ntohl); READ_SIGNED_TYPE (&mantissa, int, ntohl);
/* Assemble them into a double */ /* Assemble them into a double */
value = mantissa / FLOAT_FACTOR; value = mantissa / FLOAT_FACTOR;
value = ldexp (value, exp); value = ldexp (value, exponent);
/* Put the double into the requested memory location as a float */ /* Put the double into the requested memory location as a float */
*(float*)d = value; *(float*)d = value;
break; break;
@ -373,15 +380,16 @@ static BOOL debug_binary_coder;
case _C_DBL: case _C_DBL:
{ {
int exp, mantissa1, mantissa2; short exponent;
int mantissa1, mantissa2;
volatile double value; volatile double value;
/* Decode the exponent and the two pieces of the mantissa. */ /* Decode the exponent and the two pieces of the mantissa. */
READ_SIGNED_TYPE (&exp, int, ntohl); READ_SIGNED_TYPE (&exponent, short, ntohs);
READ_SIGNED_TYPE (&mantissa1, int, ntohl); READ_SIGNED_TYPE (&mantissa1, int, ntohl);
READ_SIGNED_TYPE (&mantissa2, int, ntohl); READ_SIGNED_TYPE (&mantissa2, int, ntohl);
/* Assemble them into a double */ /* Assemble them into a double */
value = ((mantissa2 / FLOAT_FACTOR) + mantissa1) / FLOAT_FACTOR; value = ((mantissa2 / FLOAT_FACTOR) + mantissa1) / FLOAT_FACTOR;
value = ldexp (value, exp); value = ldexp (value, exponent);
/* Put the double into the requested memory location. */ /* Put the double into the requested memory location. */
*(double*)d = value; *(double*)d = value;
break; break;