Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 18 June 2005 - 01:10 PM
Posted 18 June 2005 - 02:30 PM
Posted 18 June 2005 - 02:43 PM
Posted 18 June 2005 - 03:30 PM
double real48ToDouble(char *realValue) {
double mantissa = 1.0;
for (int i = 46; i >= 8; i--) {
if ((realValue[i / 8] >> (i % 8)) & 0x01)
mantissa += pow(2.0, i - 47);
}
char exponent = realValue[0] - 129;
if (mantissa == 1.0 && exponent == 127) // Test for null value
return 0.0;
if (realValue[5] & 0x80) // Sign bit check
mantissa *= -1.0;
return mantissa * pow(2.0, exponent);
}
Posted 18 June 2005 - 09:12 PM
double real48ToDouble(const char *realValue) {
double exponent = double((unsigned char)realValue[0]) - 129.0;
double mantissa = 1.0;
double power = 1.0;
for (int i = 46; i >= 8; i--) {
power *= 0.5;
if ((realValue[i >> 3] >> (i & 7)) & 0x01)
mantissa += power;
}
if (mantissa == 1.0 && realValue[0] == 0) // Test for null value
return 0.0;
if (realValue[5] & 0x80) // Sign bit check
mantissa = -mantissa;
return mantissa * pow(2.0, exponent);
}
Posted 19 June 2005 - 08:15 AM
Posted 19 June 2005 - 08:22 AM
Quote:You know the format of a double is a sign bit, the exponent (11 bits) and the mantissa(52 bits), right? All you have to do is swap a few bits around, prepend some zeroes to the exponent, and append some zeroes to the mantissa.
Original post by Xentropy
[...]It's not close enough to IEEE to just tack on a couple of zero bytes and call it a double. :)[...]
Posted 19 June 2005 - 09:18 AM
Posted 19 June 2005 - 09:02 PM
Posted 20 June 2005 - 10:23 AM
double Real48ToDouble(unsigned char realValue[6]) {
if (realValue[0] == 0)
return 0.0; // Null exponent = 0
double exponent = realValue[0] - 129.0;
double mantissa = 0.0;
for (int byte = 1; byte <= 4; byte++) {
mantissa += realValue[byte];
mantissa *= 0.00390625; // mantissa /= 256
}
mantissa += (realValue[5] & 0x7F);
mantissa *= 0.0078125; // mantissa /= 128
mantissa += 1.0;
if (realValue[5] & 0x80) // Sign bit check
mantissa = -mantissa;
return mantissa * pow(2.0, exponent);
}
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.