MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / quotefloat

Function quotefloat

extlibs/lua/src/lstrlib.c:1130–1151  ·  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

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