mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[cexpr] Support casting to double
For int, uint and float, also add uint to float (not that it will do any good for values over 16M).
This commit is contained in:
parent
73ab33ba97
commit
111e5d923e
1 changed files with 18 additions and 6 deletions
|
@ -45,6 +45,14 @@ pre##_##opname (const exprval_t *a, const exprval_t *b, exprval_t *c, \
|
|||
(*(type *) c->value) = (*(type *) a->value) op (*(type *) b->value); \
|
||||
}
|
||||
|
||||
#define CASTOP(dst_type, src_type) \
|
||||
static void \
|
||||
dst_type##_##cast##_##src_type (const exprval_t *a, const exprval_t *src, \
|
||||
exprval_t *res, exprctx_t *ctx) \
|
||||
{ \
|
||||
(*(dst_type *) res->value) = *(src_type *) src->value; \
|
||||
}
|
||||
|
||||
#define UNOP(pre, opname, type, op) \
|
||||
static void \
|
||||
pre##_##opname (const exprval_t *a, exprval_t *b, exprctx_t *ctx) \
|
||||
|
@ -291,12 +299,8 @@ float_div_quat (const exprval_t *val1, const exprval_t *val2,
|
|||
*c = a * qconjf (b) / dotf (b, b);
|
||||
}
|
||||
|
||||
static void
|
||||
float_cast_int (const exprval_t *val1, const exprval_t *src, exprval_t *result,
|
||||
exprctx_t *ctx)
|
||||
{
|
||||
*(float *) result->value = *(int *) src->value;
|
||||
}
|
||||
CASTOP (float, int)
|
||||
CASTOP (float, uint)
|
||||
|
||||
UNOP(float, pos, float, +)
|
||||
UNOP(float, neg, float, -)
|
||||
|
@ -313,6 +317,7 @@ binop_t float_binops[] = {
|
|||
{ '%', &cexpr_float, &cexpr_float, float_rem },
|
||||
{ MOD, &cexpr_float, &cexpr_float, float_mod },
|
||||
{ '=', &cexpr_int, &cexpr_float, float_cast_int },
|
||||
{ '=', &cexpr_uint, &cexpr_float, float_cast_uint },
|
||||
{ '=', &cexpr_plitem, &cexpr_float, cexpr_cast_plitem },
|
||||
{}
|
||||
};
|
||||
|
@ -359,6 +364,10 @@ double_mod (const exprval_t *val1, const exprval_t *val2, exprval_t *result,
|
|||
*(double *) result->value = a - b * floorf (a / b);
|
||||
}
|
||||
|
||||
CASTOP (double, int)
|
||||
CASTOP (double, uint)
|
||||
CASTOP (double, float)
|
||||
|
||||
UNOP(double, pos, double, +)
|
||||
UNOP(double, neg, double, -)
|
||||
UNOP(double, tnot, double, !)
|
||||
|
@ -370,6 +379,9 @@ binop_t double_binops[] = {
|
|||
{ '/', &cexpr_double, &cexpr_double, double_div },
|
||||
{ '%', &cexpr_double, &cexpr_double, double_rem },
|
||||
{ MOD, &cexpr_double, &cexpr_double, double_mod },
|
||||
{ '=', &cexpr_int, &cexpr_double, double_cast_int },
|
||||
{ '=', &cexpr_uint, &cexpr_double, double_cast_uint },
|
||||
{ '=', &cexpr_uint, &cexpr_double, double_cast_float },
|
||||
{ '=', &cexpr_plitem, &cexpr_double, cexpr_cast_plitem },
|
||||
{}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue