MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / math_modf

Function math_modf

lib/lua/src/lmathlib.c:139–153  ·  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

137** 'double'.
138*/
139static int math_modf (lua_State *L) {
140 if (lua_isinteger(L ,1)) {
141 lua_settop(L, 1); /* number is its own integer part */
142 lua_pushnumber(L, 0); /* no fractional part */
143 }
144 else {
145 lua_Number n = luaL_checknumber(L, 1);
146 /* integer part (rounds toward zero) */
147 lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);
148 pushnumint(L, ip);
149 /* fractional part (test needed for inf/-inf) */
150 lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));
151 }
152 return 2;
153}
154
155
156static 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