shithub: rgbds

Download patch

ref: 9b4959cb75183a866002a21371b7d09c08398045
parent: dca82e6d955641e28b95951659049ebfa55addbf
author: stag019 <[email protected]>
date: Fri Nov 7 19:17:26 EST 2014

Implement round, ceil, and floor math functions.

--- a/include/asm/mymath.h
+++ b/include/asm/mymath.h
@@ -14,5 +14,8 @@
 SLONG math_ATan2(SLONG i, SLONG j);
 SLONG math_Mul(SLONG i, SLONG j);
 SLONG math_Div(SLONG i, SLONG j);
+SLONG math_Round(SLONG i);
+SLONG math_Ceil(SLONG i);
+SLONG math_Floor(SLONG i);
 
 #endif
--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -412,7 +412,11 @@
 %left	T_OP_ATAN2
 %left	T_OP_FDIV
 %left	T_OP_FMUL
+%left	T_OP_ROUND
+%left	T_OP_CEIL
+%left	T_OP_FLOOR
 
+
 %left	T_OP_STRCMP
 %left	T_OP_STRIN
 %left	T_OP_STRSUB
@@ -953,6 +957,9 @@
 						{ rpn_Bank(&$$,$3); $$.nVal = 0; }
 				|	T_OP_DEF { oDontExpandStrings=1; } '(' T_ID ')'
 						{ rpn_Number(&$$,sym_isConstDefined($4)); oDontExpandStrings=0; }
+				|	T_OP_ROUND '(' const ')'			{ rpn_Number(&$$,math_Round($3)); }
+				|	T_OP_CEIL '(' const ')'			{ rpn_Number(&$$,math_Ceil($3)); }
+				|	T_OP_FLOOR '(' const ')'			{ rpn_Number(&$$,math_Floor($3)); }
 				|	T_OP_FDIV '(' const ',' const ')'			{ rpn_Number(&$$,math_Div($3,$5)); }
 				|	T_OP_FMUL '(' const ',' const ')'			{ rpn_Number(&$$,math_Mul($3,$5)); }
 				|	T_OP_SIN '(' const ')'			{ rpn_Number(&$$,math_Sin($3)); }
@@ -1006,6 +1013,9 @@
 				|	T_OP_ADD const %prec NEG		{ $$ = +$2; }
 				|	T_OP_SUB const %prec NEG		{ $$ = -$2; }
 				|	T_OP_NOT const %prec NEG		{ $$ = 0xFFFFFFFF^$2; }
+				|	T_OP_ROUND '(' const ')'		{ $$ = math_Round($3); }
+				|	T_OP_CEIL '(' const ')'			{ $$ = math_Ceil($3); }
+				|	T_OP_FLOOR '(' const ')'		{ $$ = math_Floor($3); }
 				|	T_OP_FDIV '(' const ',' const ')'			{ $$ = math_Div($3,$5); }
 				|	T_OP_FMUL '(' const ',' const ')'			{ $$ = math_Mul($3,$5); }
 				|	T_OP_SIN '(' const ')'			{ $$ = math_Sin($3); }
--- a/src/asm/globlex.c
+++ b/src/asm/globlex.c
@@ -267,6 +267,9 @@
 
 	{"bank", T_OP_BANK},
 
+	{"round", T_OP_ROUND},
+	{"ceil", T_OP_CEIL},
+	{"floor", T_OP_FLOOR},
 	{"div", T_OP_FDIV},
 	{"mul", T_OP_FMUL},
 	{"sin", T_OP_SIN},
--- a/src/asm/math.c
+++ b/src/asm/math.c
@@ -155,4 +155,37 @@
 math_Div(SLONG i, SLONG j)
 {
 	return (double2fix(fix2double(i) / fix2double(j)));
+}/*
+ * RGBAsm - MATH.C (Fixedpoint math routines)
+ *
+ * Round
+ *
+ */
+
+SLONG 
+math_Round(SLONG i)
+{
+	return double2fix(round(fix2double(i)));
+}/*
+ * RGBAsm - MATH.C (Fixedpoint math routines)
+ *
+ * Ceil
+ *
+ */
+
+SLONG 
+math_Ceil(SLONG i)
+{
+	return double2fix(ceil(fix2double(i)));
+}/*
+ * RGBAsm - MATH.C (Fixedpoint math routines)
+ *
+ * Floor
+ *
+ */
+
+SLONG 
+math_Floor(SLONG i)
+{
+	return double2fix(floor(fix2double(i)));
 }