tccgen: gen_cast: cast FLOAT to DOUBLE
... to avoid precision loss when casting to int, also when saving FLOATs to stack
This commit is contained in:
parent
3b84e61ead
commit
f077d16c20
1 changed files with 9 additions and 0 deletions
9
tccgen.c
9
tccgen.c
|
@ -811,6 +811,10 @@ ST_FUNC void save_reg_upstack(int r, int n)
|
||||||
#else
|
#else
|
||||||
type = &int_type;
|
type = &int_type;
|
||||||
#endif
|
#endif
|
||||||
|
if ((type->t & VT_BTYPE) == VT_FLOAT) {
|
||||||
|
/* cast to DOUBLE to avoid precision loss */
|
||||||
|
type->t = (type->t & ~VT_BTYPE) | VT_DOUBLE;
|
||||||
|
}
|
||||||
size = type_size(type, &align);
|
size = type_size(type, &align);
|
||||||
loc = (loc - size) & -align;
|
loc = (loc - size) & -align;
|
||||||
sv.type.t = type->t;
|
sv.type.t = type->t;
|
||||||
|
@ -2349,6 +2353,11 @@ static void gen_cast(CType *type)
|
||||||
vpushi(0);
|
vpushi(0);
|
||||||
gen_op(TOK_NE);
|
gen_op(TOK_NE);
|
||||||
} else {
|
} else {
|
||||||
|
if (sbt == VT_FLOAT) {
|
||||||
|
/* cast to DOUBLE to avoid precision loss */
|
||||||
|
gen_cvt_ftof(VT_DOUBLE);
|
||||||
|
vtop->type.t = (vtop->type.t & ~VT_BTYPE) | VT_DOUBLE;
|
||||||
|
}
|
||||||
/* we handle char/short/etc... with generic code */
|
/* we handle char/short/etc... with generic code */
|
||||||
if (dbt != (VT_INT | VT_UNSIGNED) &&
|
if (dbt != (VT_INT | VT_UNSIGNED) &&
|
||||||
dbt != (VT_LLONG | VT_UNSIGNED) &&
|
dbt != (VT_LLONG | VT_UNSIGNED) &&
|
||||||
|
|
Loading…
Reference in a new issue