From 1c5e917527c135ba00c06a49800d57870020f7c2 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Fri, 8 Dec 2023 17:41:22 +1000 Subject: [PATCH] Change to the C99 standard method of testing for nan This fixes all remaining strict-aliasing rule warnings in GCC. Signed-off-by: bones_was_here --- clvm_cmds.c | 4 ++-- mathlib.h | 17 ----------------- sv_phys.c | 4 ++-- svvm_cmds.c | 4 ++-- world.c | 10 +++++----- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 1e204e58..29ade032 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -296,7 +296,7 @@ static void VM_CL_traceline (prvm_prog_t *prog) move = (int)PRVM_G_FLOAT(OFS_PARM2); ent = PRVM_G_EDICT(OFS_PARM3); - if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) + if (isnan(v1[0]) || isnan(v1[1]) || isnan(v1[2]) || isnan(v2[0]) || isnan(v2[1]) || isnan(v2[2])) prog->error_cmd("%s: NAN errors detected in traceline('%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = CL_TraceLine(v1, v2, move, ent, CL_GenericHitSuperContentsMask(ent), 0, 0, collision_extendtracelinelength.value, CL_HitNetworkBrushModels(move), CL_HitNetworkPlayers(move), &svent, true, false); @@ -336,7 +336,7 @@ static void VM_CL_tracebox (prvm_prog_t *prog) move = (int)PRVM_G_FLOAT(OFS_PARM4); ent = PRVM_G_EDICT(OFS_PARM5); - if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) + if (isnan(v1[0]) || isnan(v1[1]) || isnan(v1[2]) || isnan(v2[0]) || isnan(v2[1]) || isnan(v2[2])) prog->error_cmd("%s: NAN errors detected in tracebox('%f %f %f', '%f %f %f', '%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], m1[0], m1[1], m1[2], m2[0], m2[1], m2[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = CL_TraceBox(v1, m1, m2, v2, move, ent, CL_GenericHitSuperContentsMask(ent), 0, 0, collision_extendtraceboxlength.value, CL_HitNetworkBrushModels(move), CL_HitNetworkPlayers(move), &svent, true); diff --git a/mathlib.h b/mathlib.h index e9533335..2fa93a1c 100644 --- a/mathlib.h +++ b/mathlib.h @@ -31,23 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct mplane_s; extern vec3_t vec3_origin; -#define float_nanmask (0x7F800000) -#define double_nanmask (0x7FF8000000000000) -#define FLOAT_IS_NAN(x) (((*(int *)&x)&float_nanmask)==float_nanmask) -#define DOUBLE_IS_NAN(x) (((*(long long *)&x)&double_nanmask)==double_nanmask) - -#ifdef VEC_64 -#define VEC_IS_NAN(x) DOUBLE_IS_NAN(x) -#else -#define VEC_IS_NAN(x) FLOAT_IS_NAN(x) -#endif - -#ifdef PRVM_64 -#define PRVM_IS_NAN(x) DOUBLE_IS_NAN(x) -#else -#define PRVM_IS_NAN(x) FLOAT_IS_NAN(x) -#endif - #define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) #ifndef min diff --git a/sv_phys.c b/sv_phys.c index f468a7e9..411a7c96 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -1041,12 +1041,12 @@ void SV_CheckVelocity (prvm_edict_t *ent) // for (i=0 ; i<3 ; i++) { - if (PRVM_IS_NAN(PRVM_serveredictvector(ent, velocity)[i])) + if (isnan(PRVM_serveredictvector(ent, velocity)[i])) { Con_Printf("Got a NaN velocity on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname))); PRVM_serveredictvector(ent, velocity)[i] = 0; } - if (PRVM_IS_NAN(PRVM_serveredictvector(ent, origin)[i])) + if (isnan(PRVM_serveredictvector(ent, origin)[i])) { Con_Printf("Got a NaN origin on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname))); PRVM_serveredictvector(ent, origin)[i] = 0; diff --git a/svvm_cmds.c b/svvm_cmds.c index ab9dc257..ccd7e6a9 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -662,7 +662,7 @@ static void VM_SV_traceline(prvm_prog_t *prog) move = (int)PRVM_G_FLOAT(OFS_PARM2); ent = PRVM_G_EDICT(OFS_PARM3); - if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) + if (isnan(v1[0]) || isnan(v1[1]) || isnan(v1[2]) || isnan(v2[0]) || isnan(v2[1]) || isnan(v2[2])) prog->error_cmd("%s: NAN errors detected in traceline('%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = SV_TraceLine(v1, v2, move, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendtracelinelength.value); @@ -701,7 +701,7 @@ static void VM_SV_tracebox(prvm_prog_t *prog) move = (int)PRVM_G_FLOAT(OFS_PARM4); ent = PRVM_G_EDICT(OFS_PARM5); - if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) + if (isnan(v1[0]) || isnan(v1[1]) || isnan(v1[2]) || isnan(v2[0]) || isnan(v2[1]) || isnan(v2[2])) prog->error_cmd("%s: NAN errors detected in tracebox('%f %f %f', '%f %f %f', '%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], m1[0], m1[1], m1[2], m2[0], m2[1], m2[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = SV_TraceBox(v1, m1, m2, v2, move, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendtraceboxlength.value); diff --git a/world.c b/world.c index 229fbe7e..e37b24c0 100644 --- a/world.c +++ b/world.c @@ -2733,17 +2733,17 @@ treatasbox: if (physics_ode_trick_fixnan.integer) { test = VectorLength2(origin) + VectorLength2(forward) + VectorLength2(left) + VectorLength2(up) + VectorLength2(velocity) + VectorLength2(spinvelocity); - if (VEC_IS_NAN(test)) + if (isnan(test)) { modified = true; //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]); if (physics_ode_trick_fixnan.integer >= 2) Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]); test = VectorLength2(origin); - if (VEC_IS_NAN(test)) + if (isnan(test)) VectorClear(origin); test = VectorLength2(forward) * VectorLength2(left) * VectorLength2(up); - if (VEC_IS_NAN(test)) + if (isnan(test)) { VectorSet(angles, 0, 0, 0); VectorSet(forward, 1, 0, 0); @@ -2751,10 +2751,10 @@ treatasbox: VectorSet(up, 0, 0, 1); } test = VectorLength2(velocity); - if (VEC_IS_NAN(test)) + if (isnan(test)) VectorClear(velocity); test = VectorLength2(spinvelocity); - if (VEC_IS_NAN(test)) + if (isnan(test)) { VectorClear(avelocity); VectorClear(spinvelocity); -- 2.39.2