From f4390609b35628c900afcc93287c611bc7c5747b Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Tue, 22 May 2007 23:45:53 +0000 Subject: [PATCH] re-added old float rounding native --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40842 --- core/smn_float.cpp | 37 +++++++++++++++++++++++++++++++++++++ plugins/include/float.inc | 17 +++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/core/smn_float.cpp b/core/smn_float.cpp index ffae5361..769069f2 100644 --- a/core/smn_float.cpp +++ b/core/smn_float.cpp @@ -230,6 +230,42 @@ static cell_t sm_ArcTangent2(IPluginContext *pCtx, const cell_t *params) return sp_ftoc(val1); } +static cell_t sm_FloatRound(IPluginContext *pCtx, const cell_t *params) +{ + float val = sp_ctof(params[1]); + + switch (params[2]) + { + case 1: + { + val = floor(val); + break; + } + case 2: + { + val = ceil(val); + break; + } + case 3: + { + if (val >= 0.0f) + { + val = floor(val); + } else { + val = ceil(val); + } + break; + } + default: + { + val = (float)floor(val + 0.5f); + break; + } + } + + return static_cast(val); +} + REGISTER_NATIVES(floatnatives) { {"float", sm_float}, @@ -255,5 +291,6 @@ REGISTER_NATIVES(floatnatives) {"ArcCosine", sm_ArcCosine}, {"ArcSine", sm_ArcSine}, {"ArcTangent2", sm_ArcTangent2}, + {"FloatRound", sm_FloatRound}, /* Backwards compat shim */ {NULL, NULL} }; diff --git a/plugins/include/float.inc b/plugins/include/float.inc index 619a18f8..e3de4049 100644 --- a/plugins/include/float.inc +++ b/plugins/include/float.inc @@ -212,6 +212,23 @@ native Float:ArcSine(Float:angle); */ native Float:ArcTangent2(Float:x, Float:y); +/** + * Different methods of rounding. + */ +enum floatround_method +{ + floatround_round = 0, /**< Standard IEEE rounding */ + floatround_floor, /**< Next lowest integer value. */ + floatround_ceil, /**< Next highest integer value. */ + floatround_tozero /** Closest integer to zero. */ +}; + +/** + * Backwards compatibility - use RoundToNearest or any of the other rounding natives. + * @deprecated + */ +native FloatRound(Float:value, floatround_method:method=floatround_round); + /** * User defined operators. *