MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / quotefloat

Function quotefloat

3rd/lua-5.4.3/src/lstrlib.c:1133–1154  ·  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

1131** (NaN cannot be expressed as a numeral, so we write '(0/0)' for it.)
1132*/
1133static int quotefloat (lua_State *L, char *buff, lua_Number n) {
1134 const char *s; /* for the fixed representations */
1135 if (n == (lua_Number)HUGE_VAL) /* inf? */
1136 s = "1e9999";
1137 else if (n == -(lua_Number)HUGE_VAL) /* -inf? */
1138 s = "-1e9999";
1139 else if (n != n) /* NaN? */
1140 s = "(0/0)";
1141 else { /* format number as hexadecimal */
1142 int nb = lua_number2strx(L, buff, MAX_ITEM,
1143 "%" LUA_NUMBER_FRMLEN "a", n);
1144 /* ensures that 'buff' string uses a dot as the radix character */
1145 if (memchr(buff, '.', nb) == NULL) { /* no dot? */
1146 char point = lua_getlocaledecpoint(); /* try locale point */
1147 char *ppoint = (char *)memchr(buff, point, nb);
1148 if (ppoint) *ppoint = '.'; /* change it to a dot */
1149 }
1150 return nb;
1151 }
1152 /* for the fixed representations */
1153 return l_sprintf(buff, MAX_ITEM, "%s", s);
1154}
1155
1156
1157static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {

Callers 1

addliteralFunction · 0.85

Calls 1

lua_number2strxFunction · 0.85

Tested by

no test coverage detected