From e08d1e510a2968753cab330c57e9d8ee25102aaf Mon Sep 17 00:00:00 2001
From: Kadah_Coba <kadah.coba@gmail.com>
Date: Thu, 30 Jun 2011 13:48:07 -0700
Subject: [PATCH] Additional functions for STORM-1315 Ability to do simple math
 in numeric edit fields Support for floor, ceil, modulo. Fixed ABS. Added more
 constants, SQRT_TWO_PI and SQRT3

---
 indra/llmath/llcalc.cpp     |  2 ++
 indra/llmath/llcalcparser.h | 11 ++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/indra/llmath/llcalc.cpp b/indra/llmath/llcalc.cpp
index f399463a47c..f16dbec63f5 100644
--- a/indra/llmath/llcalc.cpp
+++ b/indra/llmath/llcalc.cpp
@@ -62,7 +62,9 @@ LLCalc::LLCalc() : mLastErrorPos(0)
 	(*mConstants)["PI"] = F_PI;
 	(*mConstants)["TWO_PI"] = F_TWO_PI;
 	(*mConstants)["PI_BY_TWO"] = F_PI_BY_TWO;
+	(*mConstants)["SQRT_TWO_PI"] = F_SQRT_TWO_PI;
 	(*mConstants)["SQRT2"] = F_SQRT2;
+	(*mConstants)["SQRT3"] = F_SQRT3;
 	(*mConstants)["DEG_TO_RAD"] = DEG_TO_RAD;
 	(*mConstants)["RAD_TO_DEG"] = RAD_TO_DEG;
 	(*mConstants)["GRAVITY"] = GRAVITY;
diff --git a/indra/llmath/llcalcparser.h b/indra/llmath/llcalcparser.h
index a759a357103..600e1736610 100644
--- a/indra/llmath/llcalcparser.h
+++ b/indra/llmath/llcalcparser.h
@@ -73,7 +73,9 @@ struct LLCalcParser : grammar<LLCalcParser>
 				 (str_p("SQRT") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_sqrt)(self,arg1)]) |
 				 (str_p("LOG") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_log)(self,arg1)]) |
 				 (str_p("EXP") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_exp)(self,arg1)]) |
-				 (str_p("ABS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_fabs)(self,arg1)])
+				 (str_p("ABS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_fabs)(self,arg1)]) |
+				 (str_p("FLR") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_floor)(self,arg1)]) |
+				 (str_p("CEIL") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_ceil)(self,arg1)])
 				) >> assert_syntax(ch_p(')'))
 			;
 			
@@ -118,7 +120,8 @@ struct LLCalcParser : grammar<LLCalcParser>
 			term =
 				power[term.value = arg1] >>
 				*(('*' >> assert_syntax(power[term.value *= arg1])) |
-				  ('/' >> assert_syntax(power[term.value /= arg1]))
+				  ('/' >> assert_syntax(power[term.value /= arg1])) |
+				  ('%' >> assert_syntax(power[term.value = bind(&fmodf)(term.value, arg1)]))
 				)
 			;
 			
@@ -153,7 +156,9 @@ struct LLCalcParser : grammar<LLCalcParser>
 	F32 _sqrt(const F32& a) const { return sqrt(a); }
 	F32 _log(const F32& a) const { return log(a); }
 	F32 _exp(const F32& a) const { return exp(a); }
-	F32 _fabs(const F32& a) const { return fabs(a) * RAD_TO_DEG; }
+	F32 _fabs(const F32& a) const { return fabs(a); }
+	F32 _floor(const F32& a) const { return llfloor(a); }
+	F32 _ceil(const F32& a) const { return llceil(a); }
 
 	F32 _atan2(const F32& a,const F32& b) const { return atan2(a,b); }
 
-- 
GitLab