diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-05 14:14:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-05 14:14:29 -0300 |
commit | d30569c06407529cc6e99f4a35ae5f9bfe6fa940 (patch) | |
tree | 51e560713cb01203d94d792a1e80f38ba7f84c52 /lvm.h | |
parent | 2d92102dee88a81711dca8e8ea3ef0ea9d732283 (diff) | |
download | lua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.tar.gz lua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.tar.bz2 lua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.zip |
Using an enumeration for float->integer coercion modes
Diffstat (limited to 'lvm.h')
-rw-r--r-- | lvm.h | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -33,10 +33,20 @@ | |||
33 | ** integral values) | 33 | ** integral values) |
34 | */ | 34 | */ |
35 | #if !defined(LUA_FLOORN2I) | 35 | #if !defined(LUA_FLOORN2I) |
36 | #define LUA_FLOORN2I 0 | 36 | #define LUA_FLOORN2I F2Ieq |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | 39 | ||
40 | /* | ||
41 | ** Rounding modes for float->integer coercion | ||
42 | */ | ||
43 | typedef enum { | ||
44 | F2Ieq, /* no rounding; accepts only integral values */ | ||
45 | F2Ifloor, /* takes the floor of the number */ | ||
46 | F2Iceil, /* takes the ceil of the number */ | ||
47 | } F2Imod; | ||
48 | |||
49 | |||
40 | /* convert an object to a float (including string coercion) */ | 50 | /* convert an object to a float (including string coercion) */ |
41 | #define tonumber(o,n) \ | 51 | #define tonumber(o,n) \ |
42 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) | 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) |
@@ -104,9 +114,10 @@ LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); | |||
104 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | 114 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); |
105 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | 115 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); |
106 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); | 116 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); |
107 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); | 117 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); |
108 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, int mode); | 118 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, |
109 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, int mode); | 119 | F2Imod mode); |
120 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); | ||
110 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, | 121 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, |
111 | StkId val, const TValue *slot); | 122 | StkId val, const TValue *slot); |
112 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 123 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |