commit e22381505cb8c9e2d0598d3ff77e342b0376d6cb
parent b5ae44efb55c923a8fdec5bf5326bf92481fd3be
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sun, 2 May 2021 12:19:55 -0400
eval_cast: fix integer -> float casts
Signed-off-by: Eyal Sawady <ecs@d2evs.net>
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/eval.c b/src/eval.c
@@ -424,7 +424,16 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out)
case STORAGE_F32:
case STORAGE_F64:
case STORAGE_FCONST:
- out->constant.fval = ftrunc(to, val.constant.fval);
+ if (type_is_float(val.result)) {
+ out->constant.fval = ftrunc(to, val.constant.fval);
+ } else if (type_is_signed(val.result)) {
+ out->constant.fval =
+ ftrunc(to, (double)val.constant.ival);
+ } else {
+ assert(type_is_integer(val.result));
+ out->constant.fval =
+ ftrunc(to, (double)val.constant.uval);
+ }
return EVAL_OK;
case STORAGE_CHAR:
case STORAGE_ENUM: