commit 0bd9f47f650e1c9e01a151bf2f2d1e633543d9a3
parent e22381505cb8c9e2d0598d3ff77e342b0376d6cb
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sun, 2 May 2021 12:24:17 -0400
eval_cast: fix float -> integer casts
Signed-off-by: Eyal Sawady <ecs@d2evs.net>
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/eval.c b/src/eval.c
@@ -414,7 +414,15 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out)
case STORAGE_UINTPTR:
case STORAGE_SIZE:
case STORAGE_RUNE:
- out->constant.uval = itrunc(to, val.constant.uval);
+ if (type_is_float(val.result)) {
+ out->constant.ival =
+ itrunc(to, (intmax_t)val.constant.fval);
+ } else if (type_is_signed(val.result)) {
+ out->constant.ival = itrunc(to, val.constant.ival);
+ } else {
+ assert(type_is_integer(val.result));
+ out->constant.ival = itrunc(to, val.constant.uval);
+ }
return EVAL_OK;
case STORAGE_ARRAY:
case STORAGE_SLICE: