From ff7b1f6e5e3c7a2ef86a8ac40d30cf7f16291c75 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 28 Jul 2013 20:22:47 -0500 Subject: [PATCH] Add degree variants of FLOP operations - Added versions of the trig operations supported by FLOP that can work with degrees directly instead of radians. - Reorder FLOPs into more sensible groupings. --- src/zscript/vm.h | 27 ++++++++++++++++++--------- src/zscript/vmdisasm.cpp | 29 +++++++++++++++++++---------- src/zscript/vmexec.h | 25 +++++++++++++++++-------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/zscript/vm.h b/src/zscript/vm.h index 2d87b72091..d3e4580ce0 100644 --- a/src/zscript/vm.h +++ b/src/zscript/vm.h @@ -79,21 +79,30 @@ enum { FLOP_ABS, FLOP_NEG, - FLOP_ACOS, - FLOP_ASIN, - FLOP_ATAN, - FLOP_COS, - FLOP_COSH, FLOP_EXP, FLOP_LOG, FLOP_LOG10, - FLOP_SIN, - FLOP_SINH, - FLOP_TAN, - FLOP_TANH, FLOP_SQRT, FLOP_CEIL, FLOP_FLOOR, + + FLOP_ACOS, // This group works with radians + FLOP_ASIN, + FLOP_ATAN, + FLOP_COS, + FLOP_SIN, + FLOP_TAN, + + FLOP_ACOS_DEG, // This group works with degrees + FLOP_ASIN_DEG, + FLOP_ATAN_DEG, + FLOP_COS_DEG, + FLOP_SIN_DEG, + FLOP_TAN_DEG, + + FLOP_COSH, + FLOP_SINH, + FLOP_TANH, }; // Cast operations diff --git a/src/zscript/vmdisasm.cpp b/src/zscript/vmdisasm.cpp index 3cfcd821da..35ca6aa1f7 100644 --- a/src/zscript/vmdisasm.cpp +++ b/src/zscript/vmdisasm.cpp @@ -101,21 +101,30 @@ static const char *const FlopNames[] = { "abs", "neg", - "acos", - "asin", - "atan", - "cos", - "cosh", "exp", "log", "log10", - "sin", - "sinh", - "tan", - "tanh", "sqrt", "ceil", - "floor" + "floor", + + "acos rad", + "asin rad", + "atan rad", + "cos rad", + "sin rad", + "tan rad", + + "acos deg", + "asin deg", + "atan deg", + "cos deg", + "sin deg", + "tan deg", + + "cosh", + "sinh", + "tanh", }; static int print_reg(FILE *out, int col, int arg, int mode, int immshift, const VMScriptFunction *func); diff --git a/src/zscript/vmexec.h b/src/zscript/vmexec.h index e901e5f03d..be32dd3c11 100644 --- a/src/zscript/vmexec.h +++ b/src/zscript/vmexec.h @@ -1369,21 +1369,30 @@ static double DoFLOP(int flop, double v) { case FLOP_ABS: return fabs(v); case FLOP_NEG: return -v; + case FLOP_EXP: return exp(v); + case FLOP_LOG: return log(v); + case FLOP_LOG10: return log10(v); + case FLOP_SQRT: return sqrt(v); + case FLOP_CEIL: return ceil(v); + case FLOP_FLOOR: return floor(v); + case FLOP_ACOS: return acos(v); case FLOP_ASIN: return asin(v); case FLOP_ATAN: return atan(v); case FLOP_COS: return cos(v); - case FLOP_COSH: return cosh(v); - case FLOP_EXP: return exp(v); - case FLOP_LOG: return log(v); - case FLOP_LOG10: return log10(v); case FLOP_SIN: return sin(v); - case FLOP_SINH: return sinh(v); case FLOP_TAN: return tan(v); + + case FLOP_ACOS_DEG: return acos(v) * (180 / M_PI); + case FLOP_ASIN_DEG: return asin(v) * (180 / M_PI); + case FLOP_ATAN_DEG: return atan(v) * (180 / M_PI); + case FLOP_COS_DEG: return cos(v * (M_PI / 180)); + case FLOP_SIN_DEG: return sin(v * (M_PI / 180)); + case FLOP_TAN_DEG: return tan(v * (M_PI / 180)); + + case FLOP_COSH: return cosh(v); + case FLOP_SINH: return sinh(v); case FLOP_TANH: return tanh(v); - case FLOP_SQRT: return sqrt(v); - case FLOP_CEIL: return ceil(v); - case FLOP_FLOOR: return floor(v); } assert(0); return 0;