Run-time check for floating point byte order rather than CMake check.

It's safer not to use an unofficial CMake script.
This commit is contained in:
Tsuda Kageyu
2015-07-31 12:46:43 +09:00
parent 13dab99af0
commit 44d9f2bf25
6 changed files with 17 additions and 122 deletions

View File

@ -251,7 +251,7 @@ TFloat toFloat(const ByteVector &v, size_t offset)
} tmp;
::memcpy(&tmp, v.data() + offset, sizeof(TInt));
if(ENDIAN != Utils::FloatByteOrder)
if(ENDIAN != Utils::floatByteOrder())
tmp.i = Utils::byteSwap(tmp.i);
return tmp.f;
@ -266,7 +266,7 @@ ByteVector fromFloat(TFloat value)
} tmp;
tmp.f = value;
if(ENDIAN != Utils::FloatByteOrder)
if(ENDIAN != Utils::floatByteOrder())
tmp.i = Utils::byteSwap(tmp.i);
return ByteVector(reinterpret_cast<char *>(&tmp), sizeof(TInt));

View File

@ -248,37 +248,26 @@ namespace TagLib
#endif
#ifdef FLOAT_BYTEORDER
# if FLOAT_BYTEORDER == 1
const ByteOrder FloatByteOrder = LittleEndian;
# else
const ByteOrder FloatByteOrder = BigEndian;
# endif
#else
/*!
* Returns the IEEE754 byte order of the system.
*/
inline ByteOrder floatByteOrder()
{
double bin[] = {
// "*TAGLIB*" encoded as a little-endian floating-point number
(double) 3.9865557444897601e-105, (double) 0.0
};
union {
double d;
char c;
} u;
char *str = (char*)&bin[0];
if(strncmp(&str[1], "TAGLIB", 6) == 0)
return LittleEndian;
else
return BigEndian;
// 1.0 is stored in memory like 0x3FF0000000000000 in canonical form.
// So the first byte is zero if little endian.
u.d = 1.0;
if(u.c == 0)
return LittleEndian;
else
return BigEndian;
}
const ByteOrder FloatByteOrder = floatByteOrder();
#endif
}
}