Improve coding style in toFloat{32,64}() functions
* Use const * Don't duplicate BE/LE branches
This commit is contained in:
parent
d174f3f157
commit
a21ed51505
|
@ -113,15 +113,9 @@ CPP_UTILITIES_EXPORT constexpr uint64 toUInt64(const char *value)
|
||||||
*/
|
*/
|
||||||
CPP_UTILITIES_EXPORT inline float32 toFloat32(const char *value)
|
CPP_UTILITIES_EXPORT inline float32 toFloat32(const char *value)
|
||||||
{
|
{
|
||||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
const int32 val = toInt32(value);
|
||||||
int32 val = toInt32(value);
|
const char *const c = reinterpret_cast<const char *>(&val);
|
||||||
char *c = reinterpret_cast<char *>(&val);
|
return *reinterpret_cast<const float32 *>(c);
|
||||||
return *reinterpret_cast<float32 *>(c);
|
|
||||||
#else
|
|
||||||
int32 val = toInt32(value);
|
|
||||||
char *c = reinterpret_cast<char *>(&val);
|
|
||||||
return *reinterpret_cast<float32 *>(c);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -129,15 +123,9 @@ CPP_UTILITIES_EXPORT inline float32 toFloat32(const char *value)
|
||||||
*/
|
*/
|
||||||
CPP_UTILITIES_EXPORT inline float64 toFloat64(const char *value)
|
CPP_UTILITIES_EXPORT inline float64 toFloat64(const char *value)
|
||||||
{
|
{
|
||||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
const int64 val = toInt64(value);
|
||||||
int64 val = toInt64(value);
|
const char *const c = reinterpret_cast<const char *>(&val);
|
||||||
char *c = reinterpret_cast<char *>(&val);
|
return *reinterpret_cast<const float64 *const>(c);
|
||||||
return *reinterpret_cast<float64 *>(c);
|
|
||||||
#else
|
|
||||||
int64 val = toInt64(value);
|
|
||||||
char *c = reinterpret_cast<char *>(&val);
|
|
||||||
return *reinterpret_cast<float64 *>(c);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in New Issue