Replace type punning with explicit memcpys

pull/1992/head
Turo Lamminen 2018-06-01 12:05:42 +03:00
parent fd2a71b3fd
commit 6aa32b41a1
1 changed files with 14 additions and 6 deletions

View File

@ -98,8 +98,10 @@ AI_FORCE_INLINE bool is_qnan(float in)
// compare <register-with-different-width> against <in> // compare <register-with-different-width> against <in>
// FIXME: Use <float> stuff instead? I think fpclassify needs C99 // FIXME: Use <float> stuff instead? I think fpclassify needs C99
return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1 && _IEEESingle temp;
reinterpret_cast<_IEEESingle*>(&in)->IEEE.Frac); memcpy(&temp, &in, sizeof(float));
return (temp.IEEE.Exp == (1u << 8)-1 &&
temp.IEEE.Frac);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -114,8 +116,10 @@ AI_FORCE_INLINE bool is_qnan(double in)
// compare <register-with-different-width> against <in> // compare <register-with-different-width> against <in>
// FIXME: Use <float> stuff instead? I think fpclassify needs C99 // FIXME: Use <float> stuff instead? I think fpclassify needs C99
return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1 && _IEEEDouble temp;
reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Frac); memcpy(&temp, &in, sizeof(in));
return (temp.IEEE.Exp == (1u << 11)-1 &&
temp.IEEE.Frac);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -125,7 +129,9 @@ AI_FORCE_INLINE bool is_qnan(double in)
* @param in Input value */ * @param in Input value */
AI_FORCE_INLINE bool is_special_float(float in) AI_FORCE_INLINE bool is_special_float(float in)
{ {
return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1); _IEEESingle temp;
memcpy(&temp, &in, sizeof(float));
return (temp.IEEE.Exp == (1u << 8)-1);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -135,7 +141,9 @@ AI_FORCE_INLINE bool is_special_float(float in)
* @param in Input value */ * @param in Input value */
AI_FORCE_INLINE bool is_special_float(double in) AI_FORCE_INLINE bool is_special_float(double in)
{ {
return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1); _IEEESingle temp;
memcpy(&temp, &in, sizeof(float));
return (temp.IEEE.Exp == (1u << 11)-1);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------