MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / quotefloat

Function quotefloat

third-party/lua-5.5.0/src/lstrlib.c:1155–1176  ·  view source on GitHub ↗

** Serialize a floating-point number in such a way that it can be ** scanned back by Lua. Use hexadecimal format for "common" numbers ** (to preserve precision); inf, -inf, and NaN are handled separately. ** (NaN cannot be expressed as a numeral, so we write '(0/0)' for it.) */

Source from the content-addressed store, hash-verified

1153** (NaN cannot be expressed as a numeral, so we write '(0/0)' for it.)
1154*/
1155static int quotefloat (lua_State *L, char *buff, lua_Number n) {
1156 const char *s; /* for the fixed representations */
1157 if (n == (lua_Number)HUGE_VAL) /* inf? */
1158 s = "1e9999";
1159 else if (n == -(lua_Number)HUGE_VAL) /* -inf? */
1160 s = "-1e9999";
1161 else if (n != n) /* NaN? */
1162 s = "(0/0)";
1163 else { /* format number as hexadecimal */
1164 int nb = lua_number2strx(L, buff, MAX_ITEM,
1165 "%" LUA_NUMBER_FRMLEN "a", n);
1166 /* ensures that 'buff' string uses a dot as the radix character */
1167 if (memchr(buff, '.', cast_uint(nb)) == NULL) { /* no dot? */
1168 char point = lua_getlocaledecpoint(); /* try locale point */
1169 char *ppoint = (char *)memchr(buff, point, cast_uint(nb));
1170 if (ppoint) *ppoint = '.'; /* change it to a dot */
1171 }
1172 return nb;
1173 }
1174 /* for the fixed representations */
1175 return l_sprintf(buff, MAX_ITEM, "%s", s);
1176}
1177
1178
1179static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {

Callers 1

addliteralFunction · 0.70

Calls 1

lua_number2strxFunction · 0.70

Tested by

no test coverage detected