adjust ftoa function a bit more

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2289 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-05-19 04:22:12 +00:00
parent bb98dc4939
commit 4b88bb7293

View file

@ -331,7 +331,7 @@ int Q_strcasecmp (char *s1, char *s2)
// Q_ftoa: convert IEEE 754 float to a base-10 string with "infinite" decimal places
void Q_ftoa(char *str, float in)
{
unsigned int i = *((float *)&in);
unsigned int i = *((int *)&in);
int signbit = (i & 0x80000000) >> 31;
int exp = (signed int)((i & 0x7F800000) >> 23) - 127;
@ -353,14 +353,14 @@ void Q_ftoa(char *str, float in)
exp = -exp;
exp = (int)(exp * 0.30102999957f); // convert base 2 to base 10
exp += 11; //
exp += 8;
if (exp <= 0)
sprintf(str, "%f", in);
else
{
char tstr[8];
char *lsig = str - 1; // last significant character
char *lsig = str - 1;
sprintf(tstr, "%%.%if", exp);
sprintf(str, tstr, in);
// find last significant digit and trim