From 7b749293914183c012442a39298bb5d141aee431 Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 24 Mar 2012 06:24:56 +0000 Subject: [PATCH] * mathlib.h (IS_NAN): Fixed strict aliasing violation by providing an inline function using a float/int union instead of the original macro. git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@650 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/mathlib.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/quakespasm/Quake/mathlib.h b/quakespasm/Quake/mathlib.h index 0e85a023..b9653930 100644 --- a/quakespasm/Quake/mathlib.h +++ b/quakespasm/Quake/mathlib.h @@ -37,8 +37,16 @@ struct mplane_s; extern vec3_t vec3_origin; -#define nanmask (255<<23) /* 7F800000 */ -#define IS_NAN(x) (((*(int *) &x) & nanmask) == nanmask) +#define nanmask (255 << 23) /* 7F800000 */ +#if 0 /* macro is violating strict aliasing rules */ +#define IS_NAN(x) (((*(int *) (char *) &x) & nanmask) == nanmask) +#else +static inline int IS_NAN (float x) { + union { float f; int i; } num; + num.f = x; + return ((num.i & nanmask) == nanmask); +} +#endif #define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) //johnfitz -- from joequake