From: havoc Date: Sun, 24 Aug 2003 04:00:52 +0000 (+0000) Subject: no more uses of %g in printf as it tends to lose precision too often (this caused... X-Git-Tag: xonotic-v0.1.0preview~6418 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=eebd18fb1a1b617f7d8f454e4efbb80838331101;p=xonotic%2Fdarkplaces.git no more uses of %g in printf as it tends to lose precision too often (this caused problems with ftos in QuakeC truncating numbers to 6 digits, a problem afflicting Prydon Gate especially) still tries to print numbers briefly if possible (by checking if their value is an int) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3413 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/collision.c b/collision.c index 196dd408..20e1e767 100644 --- a/collision.c +++ b/collision.c @@ -280,11 +280,11 @@ void Collision_PrintBrushAsQHull(colbrushf_t *brush, const char *name) int i; Con_Printf("3 %s\n%i\n", name, brush->numpoints); for (i = 0;i < brush->numpoints;i++) - Con_Printf("%g %g %g\n", brush->points[i].v[0], brush->points[i].v[1], brush->points[i].v[2]); + Con_Printf("%f %f %f\n", brush->points[i].v[0], brush->points[i].v[1], brush->points[i].v[2]); // FIXME: optimize! Con_Printf("4\n%i\n", brush->numplanes); for (i = 0;i < brush->numplanes;i++) - Con_Printf("%g %g %g %g\n", brush->planes[i].normal[0], brush->planes[i].normal[1], brush->planes[i].normal[2], brush->planes[i].dist); + Con_Printf("%f %f %f %f\n", brush->planes[i].normal[0], brush->planes[i].normal[1], brush->planes[i].normal[2], brush->planes[i].dist); } void Collision_ValidateBrush(colbrushf_t *brush) diff --git a/cvar.c b/cvar.c index 790bdd05..678e01a3 100644 --- a/cvar.c +++ b/cvar.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -232,22 +232,26 @@ void Cvar_Set (const char *var_name, const char *value) Cvar_SetValue ============ */ -void Cvar_SetValueQuick (cvar_t *var, float value) +void Cvar_SetValueQuick(cvar_t *var, float value) { - char val[32]; + char val[256]; - // LordHavoc: changed from %f to %g to use shortest representation - sprintf (val, "%g",value); - Cvar_SetQuick (var, val); + if ((float)((int)value) == value) + sprintf(val, "%i", (int)value); + else + sprintf(val, "%f", value); + Cvar_SetQuick(var, val); } -void Cvar_SetValue (const char *var_name, float value) +void Cvar_SetValue(const char *var_name, float value) { - char val[32]; + char val[256]; - // LordHavoc: changed from %f to %g to use shortest representation - sprintf (val, "%g",value); - Cvar_Set (var_name, val); + if ((float)((int)value) == value) + sprintf(val, "%i", (int)value); + else + sprintf(val, "%f", value); + Cvar_Set(var_name, val); } /* diff --git a/menu.c b/menu.c index a0f4f44f..f3559bf7 100644 --- a/menu.c +++ b/menu.c @@ -1095,7 +1095,7 @@ void M_DrawSlider (int x, int y, float num, float rangemin, float rangemax) M_DrawCharacter (x + i*8, y, 129); M_DrawCharacter (x+i*8, y, 130); M_DrawCharacter (x + (SLIDER_RANGE-1)*8 * range, y, 131); - sprintf(text, "%g", num); + sprintf(text, "%f", num); M_Print(x + (SLIDER_RANGE+2) * 8, y, text); } diff --git a/pr_cmds.c b/pr_cmds.c index 47ddc33c..b45bdccc 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -1070,8 +1070,10 @@ void PF_ftos (void) v = G_FLOAT(OFS_PARM0); s = PR_GetTempString(); - // LordHavoc: ftos improvement - sprintf (s, "%g", v); + if ((float)((int)v) == v) + sprintf(s, "%i", (int)v); + else + sprintf(s, "%f", v); G_INT(OFS_RETURN) = PR_SetString(s); } diff --git a/r_shadow.c b/r_shadow.c index 320ce23e..572997ac 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2044,7 +2044,7 @@ void R_Shadow_SaveWorldLights(void) buf = NULL; for (light = r_shadow_worldlightchain;light;light = light->next) { - sprintf(line, "%s%g %g %g %g %g %g %g %d %s\n", light->castshadows ? "" : "!", light->origin[0], light->origin[1], light->origin[2], light->lightradius / r_editlights_rtlightssizescale.value, light->light[0] / r_editlights_rtlightscolorscale.value, light->light[1] / r_editlights_rtlightscolorscale.value, light->light[2] / r_editlights_rtlightscolorscale.value, light->style, light->cubemapname ? light->cubemapname : ""); + sprintf(line, "%s%f %f %f %f %f %f %f %d %s\n", light->castshadows ? "" : "!", light->origin[0], light->origin[1], light->origin[2], light->lightradius / r_editlights_rtlightssizescale.value, light->light[0] / r_editlights_rtlightscolorscale.value, light->light[1] / r_editlights_rtlightscolorscale.value, light->light[2] / r_editlights_rtlightscolorscale.value, light->style, light->cubemapname ? light->cubemapname : ""); if (bufchars + (int) strlen(line) > bufmaxchars) { bufmaxchars = bufchars + strlen(line) + 2048;