Rename the mod instruction to rem

Because % really implements remainder rather than true modulo, and I
plan on adding %% to implement true modulo.
This commit is contained in:
Bill Currie 2020-02-16 11:04:30 +09:00
parent db9996023f
commit 4269c8cb07
4 changed files with 29 additions and 13 deletions

View file

@ -181,8 +181,8 @@ typedef enum {
OP_SHL_I,
OP_SHR_I,
OP_MOD_F,
OP_MOD_I,
OP_REM_F,
OP_REM_I,
OP_LOADB_F,
OP_LOADB_V,
@ -371,7 +371,7 @@ typedef enum {
OP_MUL_VD,
OP_MUL_DV,
OP_DIV_D,
OP_MOD_D,
OP_REM_D,
OP_GE_D,
OP_LE_D,
OP_GT_D,

View file

@ -318,8 +318,8 @@ signal_hook (int sig, void *data)
else
OPC.integer_var = 0x7fffffff;
return 1;
case OP_MOD_I:
case OP_MOD_F:
case OP_REM_I:
case OP_REM_F:
OPC.integer_var = 0x00000000;
return 1;
default:
@ -1429,17 +1429,17 @@ op_call:
case OP_DIV_I:
OPC.integer_var = OPA.integer_var / OPB.integer_var;
break;
case OP_MOD_I:
case OP_REM_I:
OPC.integer_var = OPA.integer_var % OPB.integer_var;
break;
case OP_MOD_D:
case OP_REM_D:
{
double a = OPA_double_var;
double b = OPB_double_var;
OPC_double_var = a - b * trunc (a / b);
}
break;
case OP_MOD_F:
case OP_REM_F:
{
float a = OPA.float_var;
float b = OPB.float_var;

View file

@ -171,7 +171,7 @@ VISIBLE opcode_t pr_opcodes[] = {
ev_double, ev_double, ev_double,
PROG_VERSION,
},
{"%", "mod.d", OP_MOD_D, false,
{"%", "rem.d", OP_REM_D, false,
ev_double, ev_double, ev_double,
PROG_VERSION,
},
@ -1036,7 +1036,7 @@ VISIBLE opcode_t pr_opcodes[] = {
ev_integer, ev_integer, ev_integer,
PROG_VERSION,
},
{"%", "mod.i", OP_MOD_I, false,
{"%", "rem.i", OP_REM_I, false,
ev_integer, ev_integer, ev_integer,
PROG_VERSION,
},
@ -1049,7 +1049,7 @@ VISIBLE opcode_t pr_opcodes[] = {
PROG_VERSION,
},
{"%", "mod.f", OP_MOD_F, false,
{"%", "rem.f", OP_REM_F, false,
ev_float, ev_float, ev_float,
PROG_VERSION,
},

View file

@ -1,11 +1,19 @@
#pragma traditional
void printf (string ftm, ...) = #0;
void (...) printf = #0;
float snafu (float a, float b)
{
float c = a % b;
return c;
}
#pragma traditional
float foo (float a, float b)
{
float c = a % b;
return c;
}
#pragma advanced
float bar (float a, float b)
{
float c;
@ -15,11 +23,13 @@ float bar (float a, float b)
return c;
}
#pragma traditional
float baz (float a, float b)
{
float c = (a + b) % (a - b);
return c;
}
#pragma advanced
float test (string name, float (func)(float a, float b),
float a, float b, float c)
@ -45,20 +55,26 @@ float main (void)
res |= test ("foo", foo, 5, 3, 2);
res |= test ("bar", bar, 5, 3, 2);
res |= test ("baz", baz, 5, 3, 0);
res |= test ("snafu", snafu, 5, 3, 2);
res |= test ("foo", foo, -5, 3, -2);
res |= test ("bar", bar, -5, 3, -2);
res |= test ("baz", baz, -5, 3, -2);
res |= test ("snafu", snafu, -5, 3, -2);
res |= test ("foo", foo, 5, -3, 2);
res |= test ("bar", bar, 5, -3, 2);
res |= test ("baz", baz, 5, -3, 2);
res |= test ("snafu", snafu, 5, -3, 2);
res |= test ("foo", foo, -5, -3, -2);
res |= test ("bar", bar, -5, -3, -2);
res |= test ("baz", baz, -5, -3, 0);
res |= test ("snafu", snafu, -5, -3, -2);
res |= test ("foo", foo, 5, 3.5, 1.5);
res |= test ("foo", foo, -5, 3.5, -1.5);
res |= test ("snafu", snafu, 5, 3.5, 1.5);
res |= test ("snafu", snafu, -5, 3.5, -1.5);
return res;
}