webmcp

changeset 343:34bf5f7abe0d

Code cleanup in extos.c: use 1.0e9 instead of 0.000000001 to avoid floating-point inaccuracies, added "const" qualifiers to avoid two compiler warnings
author jbe
date Thu Mar 26 01:56:10 2015 +0100 (2015-03-26)
parents 061ee100f1c1
children 985ffb3ef69f
files libraries/extos/extos.c
line diff
     1.1 --- a/libraries/extos/extos.c	Tue Mar 24 23:54:14 2015 +0100
     1.2 +++ b/libraries/extos/extos.c	Thu Mar 26 01:56:10 2015 +0100
     1.3 @@ -296,8 +296,8 @@
     1.4  }
     1.5  
     1.6  static int extos_crypt(lua_State *L) {
     1.7 -  char *key;
     1.8 -  char *salt;
     1.9 +  const char *key;
    1.10 +  const char *salt;
    1.11    char *result;
    1.12    key = luaL_checkstring(L, 1);
    1.13    salt = luaL_checkstring(L, 2);
    1.14 @@ -312,7 +312,7 @@
    1.15    if (clock_gettime(CLOCK_REALTIME, &tp)) {
    1.16      return luaL_error(L, "Could not access CLOCK_REALTIME.");
    1.17    }
    1.18 -  lua_pushnumber(L, tp.tv_sec + 0.000000001 * tp.tv_nsec);
    1.19 +  lua_pushnumber(L, tp.tv_sec + tp.tv_nsec / 1.0e9);
    1.20    return 1;
    1.21  }
    1.22  
    1.23 @@ -323,7 +323,7 @@
    1.24      return luaL_error(L, "Could not access CLOCK_MONOTONIC.");
    1.25    }
    1.26    lua_pushnumber(L,
    1.27 -    tp.tv_sec + 0.000000001 * tp.tv_nsec - extos_monotonic_start_time
    1.28 +    tp.tv_sec + tp.tv_nsec / 1.0e9 - extos_monotonic_start_time
    1.29    );
    1.30    return 1;
    1.31  }
    1.32 @@ -343,7 +343,7 @@
    1.33      if (clock_gettime(CLOCK_MONOTONIC, &tp)) {
    1.34        return luaL_error(L, "Could not access monotonic hires time.");
    1.35      }
    1.36 -    extos_monotonic_start_time = tp.tv_sec + 0.000000001 * tp.tv_nsec;
    1.37 +    extos_monotonic_start_time = tp.tv_sec + tp.tv_nsec / 1.0e9;
    1.38    }
    1.39  #if LUA_VERSION_NUM >= 502
    1.40    lua_newtable(L);

Impressum / About Us