sourcemod
sourcemod copied to clipboard
format functions
Description
Why all functions that have a format argument dont indicate that the number is infinite?
Problematic Code (or Steps to Reproduce)
public void OnPluginStart()
{
float nan = 0.0/0.0;
float inf = 1.0/0.0;
PrintToServer("PrintToServer %f %f %f", nan, inf, -inf);
char buff[128];
Format(buff, sizeof(buff), "Format %f %f %f", nan, inf, -inf);
PrintToServer("%s", buff);
char fts1[10];
FloatToString(nan, fts1, sizeof(fts1));
char fts2[10];
FloatToString(inf, fts2, sizeof(fts2));
char fts3[10];
FloatToString(-inf, fts3, sizeof(fts3));
PrintToServer("FloatToString %s %s %s", fts1, fts2, fts3);
}
Logs
// PrintToServer NaN 0.000000 -0.000000 // Format NaN 0.000000 -0.000000 // FloatToString -nan(ind) inf -inf
I checked the source code of SourceMod:
-
FloatToString uses _vsnprintf or vsnprintf to format float values
-
PrintToServer and Format uses atcprintf to format float values
atcprintf uses AddFloat to format float values, and AddFloat handles NaN values in a special way, but does not handle Inf values in a special way.