mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
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:
parent
db9996023f
commit
4269c8cb07
4 changed files with 29 additions and 13 deletions
|
@ -181,8 +181,8 @@ typedef enum {
|
||||||
OP_SHL_I,
|
OP_SHL_I,
|
||||||
OP_SHR_I,
|
OP_SHR_I,
|
||||||
|
|
||||||
OP_MOD_F,
|
OP_REM_F,
|
||||||
OP_MOD_I,
|
OP_REM_I,
|
||||||
|
|
||||||
OP_LOADB_F,
|
OP_LOADB_F,
|
||||||
OP_LOADB_V,
|
OP_LOADB_V,
|
||||||
|
@ -371,7 +371,7 @@ typedef enum {
|
||||||
OP_MUL_VD,
|
OP_MUL_VD,
|
||||||
OP_MUL_DV,
|
OP_MUL_DV,
|
||||||
OP_DIV_D,
|
OP_DIV_D,
|
||||||
OP_MOD_D,
|
OP_REM_D,
|
||||||
OP_GE_D,
|
OP_GE_D,
|
||||||
OP_LE_D,
|
OP_LE_D,
|
||||||
OP_GT_D,
|
OP_GT_D,
|
||||||
|
|
|
@ -318,8 +318,8 @@ signal_hook (int sig, void *data)
|
||||||
else
|
else
|
||||||
OPC.integer_var = 0x7fffffff;
|
OPC.integer_var = 0x7fffffff;
|
||||||
return 1;
|
return 1;
|
||||||
case OP_MOD_I:
|
case OP_REM_I:
|
||||||
case OP_MOD_F:
|
case OP_REM_F:
|
||||||
OPC.integer_var = 0x00000000;
|
OPC.integer_var = 0x00000000;
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
|
@ -1429,17 +1429,17 @@ op_call:
|
||||||
case OP_DIV_I:
|
case OP_DIV_I:
|
||||||
OPC.integer_var = OPA.integer_var / OPB.integer_var;
|
OPC.integer_var = OPA.integer_var / OPB.integer_var;
|
||||||
break;
|
break;
|
||||||
case OP_MOD_I:
|
case OP_REM_I:
|
||||||
OPC.integer_var = OPA.integer_var % OPB.integer_var;
|
OPC.integer_var = OPA.integer_var % OPB.integer_var;
|
||||||
break;
|
break;
|
||||||
case OP_MOD_D:
|
case OP_REM_D:
|
||||||
{
|
{
|
||||||
double a = OPA_double_var;
|
double a = OPA_double_var;
|
||||||
double b = OPB_double_var;
|
double b = OPB_double_var;
|
||||||
OPC_double_var = a - b * trunc (a / b);
|
OPC_double_var = a - b * trunc (a / b);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OP_MOD_F:
|
case OP_REM_F:
|
||||||
{
|
{
|
||||||
float a = OPA.float_var;
|
float a = OPA.float_var;
|
||||||
float b = OPB.float_var;
|
float b = OPB.float_var;
|
||||||
|
|
|
@ -171,7 +171,7 @@ VISIBLE opcode_t pr_opcodes[] = {
|
||||||
ev_double, ev_double, ev_double,
|
ev_double, ev_double, ev_double,
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
{"%", "mod.d", OP_MOD_D, false,
|
{"%", "rem.d", OP_REM_D, false,
|
||||||
ev_double, ev_double, ev_double,
|
ev_double, ev_double, ev_double,
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
|
@ -1036,7 +1036,7 @@ VISIBLE opcode_t pr_opcodes[] = {
|
||||||
ev_integer, ev_integer, ev_integer,
|
ev_integer, ev_integer, ev_integer,
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
{"%", "mod.i", OP_MOD_I, false,
|
{"%", "rem.i", OP_REM_I, false,
|
||||||
ev_integer, ev_integer, ev_integer,
|
ev_integer, ev_integer, ev_integer,
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
|
@ -1049,7 +1049,7 @@ VISIBLE opcode_t pr_opcodes[] = {
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
|
|
||||||
{"%", "mod.f", OP_MOD_F, false,
|
{"%", "rem.f", OP_REM_F, false,
|
||||||
ev_float, ev_float, ev_float,
|
ev_float, ev_float, ev_float,
|
||||||
PROG_VERSION,
|
PROG_VERSION,
|
||||||
},
|
},
|
||||||
|
|
|
@ -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 foo (float a, float b)
|
||||||
{
|
{
|
||||||
float c = a % b;
|
float c = a % b;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
#pragma advanced
|
||||||
|
|
||||||
float bar (float a, float b)
|
float bar (float a, float b)
|
||||||
{
|
{
|
||||||
float c;
|
float c;
|
||||||
|
@ -15,11 +23,13 @@ float bar (float a, float b)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma traditional
|
||||||
float baz (float a, float b)
|
float baz (float a, float b)
|
||||||
{
|
{
|
||||||
float c = (a + b) % (a - b);
|
float c = (a + b) % (a - b);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
#pragma advanced
|
||||||
|
|
||||||
float test (string name, float (func)(float a, float b),
|
float test (string name, float (func)(float a, float b),
|
||||||
float a, float b, float c)
|
float a, float b, float c)
|
||||||
|
@ -45,20 +55,26 @@ float main (void)
|
||||||
res |= test ("foo", foo, 5, 3, 2);
|
res |= test ("foo", foo, 5, 3, 2);
|
||||||
res |= test ("bar", bar, 5, 3, 2);
|
res |= test ("bar", bar, 5, 3, 2);
|
||||||
res |= test ("baz", baz, 5, 3, 0);
|
res |= test ("baz", baz, 5, 3, 0);
|
||||||
|
res |= test ("snafu", snafu, 5, 3, 2);
|
||||||
|
|
||||||
res |= test ("foo", foo, -5, 3, -2);
|
res |= test ("foo", foo, -5, 3, -2);
|
||||||
res |= test ("bar", bar, -5, 3, -2);
|
res |= test ("bar", bar, -5, 3, -2);
|
||||||
res |= test ("baz", baz, -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 ("foo", foo, 5, -3, 2);
|
||||||
res |= test ("bar", bar, 5, -3, 2);
|
res |= test ("bar", bar, 5, -3, 2);
|
||||||
res |= test ("baz", baz, 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 ("foo", foo, -5, -3, -2);
|
||||||
res |= test ("bar", bar, -5, -3, -2);
|
res |= test ("bar", bar, -5, -3, -2);
|
||||||
res |= test ("baz", baz, -5, -3, 0);
|
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 ("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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue