From dc65323e90e1e18529e9994f670dee72cc3e81b4 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 8 Apr 2012 16:52:07 +0300 Subject: [PATCH] Calc: Added rad function (degress to radians) and fixed sgn function --- Library/MathParser.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Library/MathParser.cpp b/Library/MathParser.cpp index 3364c5b4..9be263c7 100644 --- a/Library/MathParser.cpp +++ b/Library/MathParser.cpp @@ -94,10 +94,11 @@ struct Function BYTE length; }; -static double neg(double x); static double frac(double x); static double trunc(double x); +static double rad(double deg); static double sgn(double x); +static double neg(double x); static const WCHAR* round(int paramcnt, double* args, double* result); static Function g_Functions[] = @@ -118,20 +119,21 @@ static Function g_Functions[] = { L"round", (OneArgProc)&round, 5 }, { L"asin", &asin, 4 }, { L"acos", &acos, 4 }, - { L"sgn", &sgn, 4 }, - { L"neg", &neg, 4 }, + { L"rad", &rad, 3 }, + { L"sgn", &sgn, 3 }, + { L"neg", &neg, 3 }, { L"e", NULL, 1 }, { L"pi", NULL, 2 } }; static const int FUNC_MAX_LEN = 5; static const int FUNC_ROUND = 13; -static const int FUNC_E = 18; -static const int FUNC_PI = 19; +static const int FUNC_E = 19; +static const int FUNC_PI = 20; static const BYTE FUNC_INVALID = UCHAR_MAX; static const Operation g_BrOp = { OP_OBR, 0, 0}; -static const Operation g_NegOp = { OP_FUNC_ONEARG, 17, 0 }; +static const Operation g_NegOp = { OP_FUNC_ONEARG, 18, 0 }; static const BYTE g_OpPriorities[OP_FUNC_MULTIARG + 1] = { @@ -792,6 +794,11 @@ static double trunc(double x) return (x >= 0.0) ? floor(x) : ceil(x); } +static double rad(double deg) +{ + return (deg / 180.0) * M_PI; +} + static double sgn(double x) { return (x > 0) ? 1 : (x < 0) ? -1 : 0;