From eed1ea81a1b9b9c04fad76b3f1bfeec6ea9c44db Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 24 Jun 2020 16:48:10 +0000 Subject: [PATCH] Use double for cvar values. Fixes a number of bugs caused by atof precision loss git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12732 d7cf8633-e32d-0410-b094-e92efae38249 --- cvar.c | 10 +++++----- cvar.h | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cvar.c b/cvar.c index 905fa758..aff7672a 100644 --- a/cvar.c +++ b/cvar.c @@ -111,7 +111,7 @@ match: Cvar_VariableValue ============ */ -float Cvar_VariableValueOr(cvar_state_t *cvars, const char *var_name, float def, int neededflags) +float Cvar_VariableValueOr(cvar_state_t *cvars, const char *var_name, double def, int neededflags) { cvar_t *var; @@ -459,22 +459,22 @@ void Cvar_Set_NoCallback(cvar_t *var, const char *value) Cvar_SetValue ============ */ -void Cvar_SetValueQuick(cvar_t *var, float value) +void Cvar_SetValueQuick(cvar_t *var, double value) { char val[MAX_INPUTLINE]; - if ((float)((int)value) == value) + if ((double)((int)value) == value) dpsnprintf(val, sizeof(val), "%i", (int)value); else dpsnprintf(val, sizeof(val), "%f", value); Cvar_SetQuick(var, val); } -void Cvar_SetValue(cvar_state_t *cvars, const char *var_name, float value) +void Cvar_SetValue(cvar_state_t *cvars, const char *var_name, double value) { char val[MAX_INPUTLINE]; - if ((float)((int)value) == value) + if ((double)((int)value) == value) dpsnprintf(val, sizeof(val), "%i", (int)value); else dpsnprintf(val, sizeof(val), "%f", value); diff --git a/cvar.h b/cvar.h index e7234b17..aa36f626 100644 --- a/cvar.h +++ b/cvar.h @@ -124,8 +124,8 @@ typedef struct cvar_s const char *string; const char *description; int integer; - float value; - float vector[3]; + double value; + double vector[3]; const char *defstring; @@ -141,8 +141,8 @@ typedef struct cvar_s const char *initstring; const char *initdescription; int initinteger; - float initvalue; - float initvector[3]; + double initvalue; + double initvector[3]; const char *initdefstring; int globaldefindex[3]; @@ -193,12 +193,12 @@ void Cvar_Set (cvar_state_t *cvars, const char *var_name, const char *value); void Cvar_Set_NoCallback (cvar_t *var, const char *value); /// expands value to a string and calls Cvar_Set -void Cvar_SetValue (cvar_state_t *cvars, const char *var_name, float value); +void Cvar_SetValue (cvar_state_t *cvars, const char *var_name, double value); void Cvar_SetQuick (cvar_t *var, const char *value); -void Cvar_SetValueQuick (cvar_t *var, float value); +void Cvar_SetValueQuick (cvar_t *var, double value); -float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, float def, int neededflags); +float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, double def, int neededflags); // returns def if not defined float Cvar_VariableValue (cvar_state_t *cvars, const char *var_name, int neededflags); -- 2.39.2