MCPcopy Create free account
hub / github.com/DFHack/dfhack / math_modf

Function math_modf

depends/lua/src/lmathlib.c:149–163  ·  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

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

Callers

nothing calls this directly

Calls 5

lua_isintegerFunction · 0.85
lua_settopFunction · 0.85
lua_pushnumberFunction · 0.85
luaL_checknumberFunction · 0.85
pushnumintFunction · 0.85

Tested by

no test coverage detected