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

Function math_modf

third-party/lua-5.5.0/src/lmathlib.c:146–160  ·  view source on GitHub ↗

** next function does not use 'modf', avoiding problems with 'double*' ** (which is not compatible with 'float*') when lua_Number is not ** 'double'. */

Source from the content-addressed store, hash-verified

144** 'double'.
145*/
146static int math_modf (lua_State *L) {
147 if (lua_isinteger(L ,1)) {
148 lua_settop(L, 1); /* number is its own integer part */
149 lua_pushnumber(L, 0); /* no fractional part */
150 }
151 else {
152 lua_Number n = luaL_checknumber(L, 1);
153 /* integer part (rounds toward zero) */
154 lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);
155 pushnumint(L, ip);
156 /* fractional part (test needed for inf/-inf) */
157 lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));
158 }
159 return 2;
160}
161
162
163static int math_sqrt (lua_State *L) {

Callers

nothing calls this directly

Calls 5

lua_isintegerFunction · 0.70
lua_settopFunction · 0.70
lua_pushnumberFunction · 0.70
luaL_checknumberFunction · 0.70
pushnumintFunction · 0.70

Tested by

no test coverage detected