]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
ftos_slow terencehill/ftos_slow
authorterencehill <piuntn@gmail.com>
Thu, 25 Jun 2020 15:57:42 +0000 (17:57 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 25 Jun 2020 17:57:06 +0000 (19:57 +0200)
prvm_edict.c

index 875d52c600f1df01e8c4e93b308e506c59cc0aab..83d194d3453915d614144031e37009e2a19b73e6 100644 (file)
@@ -2391,7 +2391,9 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da
                        if(!cvar)
                        {
                                const char *value;
-                               char buf[64];
+                               char buf[128];
+                               int prec[3];
+                               float f;
                                Con_DPrintf("PRVM_LoadProgs: no cvar for autocvar global %s in %s, creating...\n", name, prog->name);
                                switch(prog->globaldefs[i].type & ~DEF_SAVEGLOBAL)
                                {
@@ -2399,11 +2401,33 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da
                                                if((float)((int)(val->_float)) == val->_float)
                                                        dpsnprintf(buf, sizeof(buf), "%i", (int)(val->_float));
                                                else
-                                                       dpsnprintf(buf, sizeof(buf), "%.9g", val->_float);
+                                               {
+                                                       // ftos_slow
+                                                       f = val->_float;
+                                                       for (int precision = 7; precision <= 9; ++precision) {
+                                                               dpsnprintf(buf, sizeof(buf), "%.*g", precision, f);
+                                                               if ((float)atof(buf) == f) {
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
                                                value = buf;
                                                break;
                                        case ev_vector:
-                                               dpsnprintf(buf, sizeof(buf), "%.9g %.9g %.9g", val->vector[0], val->vector[1], val->vector[2]); value = buf;
+                                               for (i = 0; i < 3; ++i)
+                                               {
+                                                       prec[i] = 9;
+                                                       f = val->vector[i];
+                                                       for (int precision = 7; precision <= 9; ++precision) {
+                                                               dpsnprintf(buf, sizeof(buf), "%.*g", precision, f);
+                                                               if ((float)atof(buf) == f) {
+                                                                       prec[i] = precision;
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                               dpsnprintf(buf, sizeof(buf), "%.*g %.*g %.*g", prec[0], val->vector[0], prec[1], val->vector[1], prec[2], val->vector[2]);
+                                               value = buf;
                                                break;
                                        case ev_string:
                                                value = PRVM_GetString(prog, val->string);