1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00

Allow floating point constants to be converted to integer (warning if loss of precision)

This commit is contained in:
bbbradsmith 2023-05-02 23:57:32 -04:00
parent a686d1fa8e
commit 52f0e6a29c

View File

@ -123,6 +123,16 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
** to handle sign extension correctly.
*/
/* If this is a floating point constant, convert to integer,
** and warn if precision is discarded.
*/
if (IsClassFloat (OldType) && IsClassInt (NewType)) {
long IVal = (long)Expr->V.FVal.V;
if (Expr->V.FVal.V != FP_D_FromInt(IVal).V)
Warning ("Floating point constant (%f) converted to integer loses precision (%d)",Expr->V.FVal.V,IVal);
Expr->IVal = IVal;
}
/* Check if the new datatype will have a smaller range. If it
** has a larger range, things are OK, since the value is
** internally already represented by a long.