mirror of
https://github.com/cc65/cc65.git
synced 2025-03-04 00:30:35 +00:00
Allow floating point constants to be converted to integer (warning if loss of precision)
This commit is contained in:
parent
a686d1fa8e
commit
52f0e6a29c
@ -123,6 +123,16 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
** to handle sign extension correctly.
|
** 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
|
/* Check if the new datatype will have a smaller range. If it
|
||||||
** has a larger range, things are OK, since the value is
|
** has a larger range, things are OK, since the value is
|
||||||
** internally already represented by a long.
|
** internally already represented by a long.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user