mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement round, ceil, and floor math functions.
This commit is contained in:
@@ -14,5 +14,8 @@ SLONG math_ATan(SLONG i);
|
||||
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
|
||||
|
||||
@@ -412,6 +412,10 @@ void if_skip_to_endc( void )
|
||||
%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
|
||||
@@ -953,6 +957,9 @@ relocconst : T_ID
|
||||
{ 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 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
|
||||
| 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); }
|
||||
|
||||
@@ -267,6 +267,9 @@ struct sLexInitString staticstrings[] = {
|
||||
|
||||
{"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},
|
||||
|
||||
@@ -155,4 +155,37 @@ SLONG
|
||||
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)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user