mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Trim the trailing zeros off floats for cvars
This commit is contained in:
parent
b38921ff53
commit
5b08e1802d
4 changed files with 36 additions and 4 deletions
|
@ -823,8 +823,13 @@ static void COM_Help_f(void)
|
|||
if (!stricmp(cvar->PossibleValue[MINVAL].strvalue, "MIN"))
|
||||
{
|
||||
if (floatmode)
|
||||
CONS_Printf(" range from %f to %f\n", FIXED_TO_FLOAT(cvar->PossibleValue[MINVAL].value),
|
||||
FIXED_TO_FLOAT(cvar->PossibleValue[MAXVAL].value));
|
||||
{
|
||||
float fu = FIXED_TO_FLOAT(cvar->PossibleValue[MINVAL].value);
|
||||
float ck = FIXED_TO_FLOAT(cvar->PossibleValue[MAXVAL].value);
|
||||
CONS_Printf(" range from %ld%s to %ld%s\n",
|
||||
(long)fu, M_Ftrim(fu),
|
||||
(long)ck, M_Ftrim(ck));
|
||||
}
|
||||
else
|
||||
CONS_Printf(" range from %d to %d\n", cvar->PossibleValue[MINVAL].value,
|
||||
cvar->PossibleValue[MAXVAL].value);
|
||||
|
@ -973,7 +978,10 @@ static void COM_Add_f(void)
|
|||
}
|
||||
|
||||
if (( cvar->flags & CV_FLOAT ))
|
||||
CV_Set(cvar, va("%f", FIXED_TO_FLOAT (cvar->value) + atof(COM_Argv(2))));
|
||||
{
|
||||
float n =FIXED_TO_FLOAT (cvar->value) + atof(COM_Argv(2));
|
||||
CV_Set(cvar, va("%ld%s", (long)n, M_Ftrim(n)));
|
||||
}
|
||||
else
|
||||
CV_AddValue(cvar, atoi(COM_Argv(2)));
|
||||
}
|
||||
|
|
|
@ -2915,7 +2915,8 @@ static void M_ChangeCvar(INT32 choice)
|
|||
|| !(currentMenu->menuitems[itemOn].status & IT_CV_INTEGERSTEP))
|
||||
{
|
||||
char s[20];
|
||||
sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f));
|
||||
float n = FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f);
|
||||
sprintf(s,"%ld%s",(long)n,M_Ftrim(n));
|
||||
CV_Set(cv,s);
|
||||
}
|
||||
else
|
||||
|
|
17
src/m_misc.c
17
src/m_misc.c
|
@ -2581,3 +2581,20 @@ int M_JumpWordReverse(const char *line, int offset)
|
|||
offset--;
|
||||
return offset;
|
||||
}
|
||||
|
||||
const char * M_Ftrim (double f)
|
||||
{
|
||||
static char dig[9];/* "0." + 6 digits (6 is printf's default) */
|
||||
int i;
|
||||
/* I know I said it's the default, but just in case... */
|
||||
sprintf(dig, "%.6g", modf(f, &f));
|
||||
if (dig[0])
|
||||
{
|
||||
for (i = strlen(dig); dig[i] == '0'; --i)
|
||||
;
|
||||
dig[i + 1] = '\0';
|
||||
return &dig[1];/* skip the 0 */
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -109,6 +109,12 @@ int M_JumpWord (const char *s);
|
|||
/* E.g. cursor = M_JumpWordReverse(line, cursor); */
|
||||
int M_JumpWordReverse (const char *line, int offset);
|
||||
|
||||
/*
|
||||
Return dot and then the fractional part of a float, without
|
||||
trailing zeros, or "" if the fractional part is zero.
|
||||
*/
|
||||
const char * M_Ftrim (double);
|
||||
|
||||
// counting bits, for weapon ammo code, usually
|
||||
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
||||
|
||||
|
|
Loading…
Reference in a new issue